Skip to content

Live and Copy Databases

A database is either live or a copy, and only the live database talks to the outside world. A developer restoring production onto a laptop, a staging copy, a restored backup, a demo session: each of them is a copy, with nothing to configure. A copy:

  • sends no email, SMS or other messages (each one is recorded as sent, and nothing leaves);
  • sends no web push notifications;
  • runs no scheduled jobs;
  • charges no saved cards and calls no outgoing webhooks;
  • does not connect to any integration in Live mode — payments, shipping carriers, bank feeds, tax filing, e-invoicing, marketplaces. Test mode keeps working, so a copy can still run a whole flow against a vendor’s sandbox;
  • does not fetch mail, sync calendars or check in with the licence server.

Reads, the interface and everything inside the database work normally. Every user sees a notice at the top of the screen while the database is a copy.

A database records, inside itself, the PostgreSQL identity it was declared live under. Every way of copying a database with PostgreSQL — pg_dump into another database, CREATE DATABASE ... TEMPLATE, a restore onto other hardware — produces a database with a new identity, so the record no longer matches and the database is a copy. Databases cloned or restored from the database manager are marked as copies explicitly.

A database created on this server is live from the start. Databases that existed before this mechanism are recorded as live when they are upgraded, so an upgrade never changes how an existing database behaves.

When a copy really is the live database — a restore after losing the original server — declare it, either from the app or the command line:

  • an administrator presses This Is My Live Database on the notice;
  • or fullfinity-server -c config.yaml adopt --db <name> (--status reports without changing anything, and exits non-zero while the database is not live).

Adopting also gives the database ownership of its files (see Multi-tenancy). If the database it was copied from is still running, stop it first: two live databases would email the same customers and delete each other’s files.

A copy meant to stand beside the original — staging — is never adopted. Give it files of its own with fullfinity-server filestore fork --db <name>; it stays a copy.

FULLFINITY_ENV, set as an environment variable or in config.yaml, takes production (the default), staging or test. Set to staging or test, it means no database on the server is live, whatever their records say:

FULLFINITY_ENV: staging

It can only make a server safer: it never makes a copy live, and a database on a staging or test server cannot be adopted from the app. Use it for a server that exists only for testing, including one whose databases are disk snapshots of production (a snapshot is an identical cluster, so it is not recognised as a copy on its own).

An integration that calls a vendor should resolve its host through api_base_url. That already refuses a Live integration in a database that is not live, with a message telling the user to switch to Test mode:

async def _myvendor_base_url(self):
return await self.api_base_url(MYVENDOR_SANDBOX, MYVENDOR_PRODUCTION)

A provider with no test environment, such as a marketplace or a calendar, refuses before it reaches out:

async def _myvendor_client(self):
await self.refuse_unless_live() # raises a clear message in a copy
...

Any other outbound effect asks directly:

from fullfinity.engine.environment import is_live
async def push_to_partner(self):
if not await is_live():
return # a copy of the database: nothing real happens
...

Decide what a copy should do: refuse with a message when a person pressed a button and is owed a reason, or skip quietly when the effect is a side effect of something else (saving a meeting in a copy still saves it; it just is not mirrored to the user’s calendar).

fullfinity-server check --only outbound fails on any module file that imports a network library (httpx, aiohttp, requests, smtplib, imaplib, poplib, urllib.request) without saying what it does in a copy: resolving its host through api_base_url, calling is_live() or refuse_unless_live(), or carrying a declaration with its reason:

# outbound: reads public exchange rates.
import httpx

The reason is read by whoever reviews the module, so make it true and specific. A declaration with no reason fails.