Data and migrations
On this page
$ npx globetrotter sync # writes the next migration, if the design moved
$ cd backend && GLOBETROTTER_ENV=local uv run python -m <app>_core.migrate # applies it
db: applied 0001, 0002Your database changes on purpose, in files you can read. Sync writes them; you apply them. A studio save never writes or applies one.
How a migration is written
Core compares the service design with the copy of it the last migration was
written from (kept in designs/.memory/synced/) and writes the next
migration of each store that moved. For each engine the store is on, it writes
one SQL file:
backend/migrations/<store>/<engine>/0001_init.sql
backend/migrations/<store>/<engine>/0003_changes.sqlThe first is 0001_init.sql. A later one is named for its change when there is
one change, else changes. The header says it is written
once from the design and never regenerated: read it, edit it if you need to,
then apply it. A migration is frozen once written. Between syncs the entities
follow the design, and the database waits for the next sync and a deliberate
migrate.
A hand-written migration chains after the written ones. New ones append after the head. Sample rows are not one: see Sample rows.
Starting again before anything is applied
Removing the starter item entity after one sync writes 0002_changes.sql with
DESTRUCTIVE: drops the item table and every row in it. Core cannot know what a
database has applied, so the words say both: nothing is dropped until that migration
is applied, and if you have applied none yet, start again with one command:
globetrotter sync --restart-migrations (an agent: regenerate with migrate: "restart"). It moves backend/migrations and the synced copies into backend/migrations.aside-<n>/ (never deleted), says to delete or move the local database file yourself if it was migrated, and writes one 0001_init.sql from the design as it is. A server database, or more than three migrations, is refused until --yes says none has been applied. init writes no migration: the first sync after you model your entities writes the one 0001.
Destructive changes are said
Each change that can lose or refuse data is written into the file as a comment,
and sync says the same lines beside the file's name:
DESTRUCTIVE:a dropped column, a dropped table.NOTE:a unique index where rows may share a value; a field made required; a longest length that existing rows may exceed; a link turned NOT NULL.
Turning unique on for a field that is there, or adding a column unique, writes
an index of its own (<table>_<column>_unique), and the note gives the query
that finds rows sharing a value (SELECT … GROUP BY … HAVING COUNT(*) > 1).
Turning it off drops that index; what an engine cannot do in place is said in the
file (Limits).
A real note from fieldops:
-- NOTE: job.site changes its longest from any length to 120: on postgres and mysql the change fails where a value is longer, so shorten those first; …Nothing destructive runs unread.
Under each migration it writes, sync also says what its SQL does to the rows
already there, from the statements: renames the column title to name: rows stay, rebuilds the table job, copying its rows: rows stay, moves each assignee_id of job into job_assignee, then drops the column: nothing is lost,
DROPS the column site of job: its values are lost when this is applied, DROPS the table …, and the rules that can fail on rows (makes … required, makes … unique, a type change, a link rule, a check). A closing line, last so the eye
ends on it, says when the lint found errors: ! 2 lint errors above: the files were written anyway …; sync --check fails on them.
Add a field to an entity that has rows
$ npx globetrotter sync
✗ designs/my-api.service.json: note.pinned is a new required field with no default, and note has a table already: … Instead: give it a default (set_service_props pinned default "false": old rows get false), or make it optional (required: false).A required field has to have a value on every row, and the rows already there
have none. So a new field on an entity that has a table is refused unless it has
a default (old rows get it) or is optional. Add it as a boolean pinned with
"default": "false" and sync writes ALTER TABLE "note" ADD COLUMN "pinned" INTEGER NOT NULL DEFAULT 0; (sqlite, in place, no rebuild), says adds pinned to note: existing rows get 0, and after the migrate a list answers pinned: false
on every old row and a create fills it by itself. A field made required later
is held the same way; with a default, the migration first fills the rows that
have none (UPDATE … WHERE … IS NULL). Only the change is refused, never a
design already synced.
What the newer parts write
| Change in the design | The migration |
|---|---|
A relation turned joined (many to many) |
A join table, named after the relation, with both links and the owner's onDelete. Where the relation was one to many, the links the child's column held are copied in before the column goes. A relation through an entity makes no table: the entity's own is the join. |
An enum's values changed (a state added) |
postgres: the column's CHECK dropped and made again. sqlite: the table rebuilt inside the migration, unless another table points at it or a search is built on it; then a recipe in comments and a NOTE. mysql: a recipe and a NOTE. A value taken away is DESTRUCTIVE: a row still holding it stops the migration. |
| Tenants turned on | audit_log gains a tenant column; a NOTE for rows that belong to no organisation yet (they match no request until given one); with tenancy.rls, on postgres only, ENABLE ROW LEVEL SECURITY and a policy per table, with a NOTE on the role it needs. |
Nothing: a project whose audit_log was made before 2026-11-14 |
The next sync writes one numbered migration, <n>_add_audit_operation.sql (ALTER TABLE "audit_log" ADD COLUMN "operation" TEXT;), with a NOTE that rows kept before it say no operation. It is read from the migrations on disk, not from a change in the design. fieldops got 0009, storefront 0012, mail 0004; you apply it, as any other. Applied on sqlite by fieldops' own runner to a database with rows (python-audit-operation.txt); postgres and mysql written, not run. |
| A webhook with an event id | The webhook_event table. Taking the last one away drops it, marked DESTRUCTIVE. |
An entity turned versioned |
A column version: INTEGER NOT NULL DEFAULT 1 on sqlite, BIGINT NOT NULL DEFAULT 1 on postgres and mysql. On a table that exists it is one ALTER TABLE … ADD COLUMN, with a NOTE: item is versioned now: every item that exists is at version 1, and each write raises it by one. Turning it off drops the column, marked DESTRUCTIVE: drops item's version: a stale write is no longer refused. Only the sqlite file has been applied to a database. |
A relation's onDelete changed, or the entity it points at |
postgres: <table>_<column>_fkey dropped and added again. mysql: its named constraint dropped and added (written, not run). sqlite: a NOTE and the table's rebuild as comments, to run by hand with foreign keys off; until then the table keeps the old rule and the generated delete refuses first. Fieldops' 0007_on_delete_job_assignee_id.sql is one: -- sqlite keeps job.assignee_id ON DELETE SET NULL: it cannot change a foreign key in place. |
Tables dropped in one migration go in an order the database accepts: a table
that points at another is dropped first, on every engine. For tables that
point at each other, postgres and mysql drop the keys between them first, then
the tables; sqlite's file sets PRAGMA defer_foreign_keys = ON, so the checks
wait until both are gone. The sqlite file was applied to a database in a test;
postgres and mysql are written, not run.
Not written: changing a joined relation's onDelete after its join table
exists writes no migration (a relation's own onDelete does: postgres and
mysql make its constraint again, sqlite's file is a rebuild recipe). A rebuild of a table other tables point at needs
foreign keys off, which sqlite allows only outside a transaction, so that one is
a recipe you run by hand (Limits).
Renames
A renamed field or entity is a RENAME in the migration, so the values stay.
Nodes are matched by id, so a rename in the design is never a drop and an add.
A renamed table or link column takes its key's name along, so a later change
or drop finds <table>_<column>_fkey: postgres writes RENAME CONSTRAINT,
mysql drops the key and adds it under the new name (on a table from before
2026-11-13 there is no key to drop: the file says to delete that line). Written,
not run on either.
After a rename, sync and service_status name each file of yours that still
says the old name. See Generated code.
Applying
$ cd backend
$ GLOBETROTTER_ENV=local uv run python -m <app>_core.migrate [store] [revision]It prints one line per store: db: applied 0001, 0002, or
db: up to date, nothing to apply, or db: no migrations yet before the first
sync. Alembic runs the SQL files for the connected engine.
A migration that fails is rolled back and said in words: which failed, what
was applied before it, and what to read (its NOTE lines say what to check).
The database is left where it was. Fix the rows or the file, then run it
again.
Not on mysql. There each CREATE, ALTER and DROP is kept as it runs, so
what the file did before the failing statement stays. The runner says so:
db: migration 0003 failed part way: … On mysql each CREATE, ALTER and DROP is
kept as it runs, so what 0003 did before the failing statement is still in the
database. No migration before it was applied in this run. Put the database
right by hand …Put it right by hand or restore, then run it again (transcript).
Each migration runs in one transaction with its version row (postgres; sqlite
too, begun with BEGIN IMMEDIATE): a crash between the two cannot leave the
schema changed and the number not.
One runner at a time per database. A second one started together waits, then
finds the work done: db: up to date, nothing to apply (waited 0.2 s for another migrate to finish). Postgres: a session advisory lock; mysql: GET_LOCK;
sqlite: flock on <file>.migrate-lock beside the database (POSIX only), then
each revision's BEGIN IMMEDIATE. It waits GLOBETROTTER_MIGRATE_LOCK_TIMEOUT
seconds (300), then stops in a sentence, nothing applied.
On a database Python's runner applies (it has alembic_version), the Rust
migrate writes nothing and says whose it is: migrated by the python target's runner (alembic_version at 0003): nothing to do here. With migrations on disk
ahead of that version it stops and names uv run python -m <app>_core.migrate;
_<app>_migrations is only ever the Rust runner's own table, on a database
Python did not migrate.
When the project has no Python target any more, the same database is refused:
migrated by a Python backend … nothing was applied, naming its own URL to give
Rust. Rust does not adopt a database another runner recorded. An
alembic_version that is not one of the project's migrations is refused in
words, never read as a number of them.
The Rust runner (cargo run -p <app> -- migrate) takes the same lock, by the
same name, key and file, so a Python and a Rust runner started together
exclude each other, and the one that waited says how long
(transcript).
Going back
$ uv run python -m <app>_core.migrate --down # one migration
$ uv run python -m <app>_core.migrate --down --to 0002 # back to 0002 (0000: none)Each migration sync writes has a down file beside it,
migrations/<store>/<engine>/down/NNNN_<name>.sql: the design run the other
way (a made table, column or index dropped, a rename renamed back), checked to
take away everything the up made. Where that cannot be honest, the file is one
-- REFUSED: line saying why: the up threw data away (a dropped column, a
state taken out), left a recipe for a person, or made something the way back
does not name. A migration written by hand (a seed) has no down until you
write one. Every down on the way is read first; one refused or missing stops
the run with nothing undone:
db: migration 0004 cannot be undone: 0004 threw data away (drops job.checklist and every value in it): no file can put it back. Restore a backup taken before 0004 was applied. Nothing was undone.Outside local it asks for --yes: a down drops what its migration made,
rows included. Migrations written before this have no down file
(transcript). This is Python's runner: the Rust migrate takes no argument (--down is refused, exit 2) and has no way back; read in tools.rs and repos.rs, not run.
A backend started before its migrations ran says which are waiting and the
command to run, and answers 503 in those words until they have. /ready asks
for the revisions the running code was generated with, not for the files on
disk, so a rollout can run an additive
migration under the old code.
A save is ahead of the database
A studio save changes the service design and regenerates the entities, and
writes no migration (sync does) and applies none. The running backend (dev
reloads it on the new entities) is then ahead of its database. It does not fail
queries into 500s: when a statement the database refused fails a request, the
backend holds what the entities map (each table and column, and each join table
with its two columns) against the database's own columns (not against migration
files, which do not exist yet) and answers 503 naming the column and the two
commands, npx globetrotter sync, then
GLOBETROTTER_ENV=local uv run python -m <app>_core.migrate in the backend's
folder. Outside local the 503's body is the plain sentence ("The service is not
ready: its database is behind it. Try again in a moment.") and the detail stays in
the log line and /ready. The log gets the line once a minute, not a traceback
per request. The whole answer, empty too, is kept two seconds and requests that
fail together share one check, so a working request costs nothing and a burst of
failing ones inspects the database once; a migration applied is seen within two
seconds. A pool that timed out or closed, a panic and your own Error::failed
never ask: they stay the 500 they are. Reads of entities the save did not touch
keep answering 200 (transcript).
The Rust build is compiled, so a save cannot change a running binary: the
rebuild after a save and before sync is the same gap, and it answers the same
503 in the same words (the one difference is the runner's command,
GLOBETROTTER_ENV=local cargo run -p <app> -- migrate, or Python's where
Python's runner applied the database). The columns its models map are a list
kept in the generated crate per store, held against the database's own (sqlite's
pragma_table_info, information_schema on postgres and mysql) by the same
rules; /ready and the start line say it
(transcript: sqlite only; the
postgres and mysql queries are in the generated code and not run).
An engine change can bring a migration of its own with no design change, as the
audit row's operation column did (fieldops 0009_add_audit_operation.sql):
run migrate, then start. Code started first says the same on start, on
/ready, on an audited write and in the audit reader, and a read still answers
(python-audit-operation.txt):
The database is not ready: db is at 0008, 0009 is waiting: in the backend's folder, run GLOBETROTTER_ENV=local uv run python -m fieldops_core.migrate.
$ uv run python -m fieldops_core.audit --limit 1
The audit could not be read: the database is not ready: db is at 0008, 0009 is waiting: in the backend's folder, run GLOBETROTTER_ENV=local uv run python -m fieldops_core.migrate.Rust runs the same files with sqlx::migrate!. On a database Python's runner
applied it refuses it when Python is not among the project's targets; when it is,
migrate says there is nothing to do there and Python's runner applies what waits. Started ahead of its database it says the same: the
start line, /ready 503, an audited command 503 (not 500) and the audit
reader's sentence. The sentence names the runner that owns the database:
uv run python -m <app>_core.migrate where Python's runner applied it,
cargo run -p <app> -- migrate otherwise.
Engines
| Engine | Entities and migrations | Run against a server here |
|---|---|---|
| sqlite | Yes | Yes. mail and storefront run on it. |
| postgres | Yes | fieldops ships on it (16 November): Python backend and tests on Postgres 16 (transcript); earlier scratch runs of its Python backend (transcript) and its Rust crate (transcript). |
| mysql | Yes | Once: fieldops' Python backend on MySQL 8.4 (transcript). Rust: no. |
fieldops' own database is Postgres, from its compose file (Docker or OrbStack;
no .env needed). From the repository root, then backend/:
$ docker compose -f examples/fieldops/backend/compose.yaml up -d db # postgres 16 on 127.0.0.1:5440
$ cd examples/fieldops/backend && GLOBETROTTER_ENV=local uv run python -m fieldops_core.migrate
db: applied 0001, 0002
$ GLOBETROTTER_DB_TEST_URL=postgres://fieldops:fieldops-dev@127.0.0.1:5440/fieldops_test uv run pytest -q
69 passed in 21.76sThe run empties the database GLOBETROTTER_DB_TEST_URL names, so its name must
say test (fieldops_test is made by the compose file); without the variable
the suite refuses. npm run dev:fieldops with no database up stops at once and
names the compose command. The 69 press the app in process on that database
(transcript). Rust's twin, in
backend/, with the same database:
$ GLOBETROTTER_DB_TEST_URL=postgres://fieldops:fieldops-dev@127.0.0.1:5440/fieldops_test cargo test --locked -p fieldops-generatedWithout the variable its database presses are skipped, or fail under CI or GLOBETROTTER_REQUIRE_DB=1 (the variables); a database whose name does not say test is refused
(transcript).
The scratch runs before this one were 29 passed, 40 skipped on Postgres 16
and on MySQL 8.4: the 29 are Schemathesis against the served backend; the 40
press the app in process on a sqlite file and were skipped. On mysql the Python runner runs a file one statement at a time, and a
default on a TEXT or JSON column is written DEFAULT ('Open').
An engine added later starts from the present. Its 0001 is the schema as it
is now, and each later number the first engine has is written for it too: a
file named NNNN_nothing_here.sql, a header and a note, when that revision
holds nothing for it. Every engine keeps every number.
$ globetrotter sync
→ backend/migrations/db/postgres/0001_init.sql (NOTE: written later than sqlite's 0001, …)
$ grep -n operation backend/migrations/db/postgres/0001_init.sql
16: "operation" TEXTWhere two engines already disagree on a column of audit_log, the
ADD COLUMN is written only for the engine that lacks it; the other's file at
that number says there is nothing to add
(transcript). An engine that has
some revisions and not others is written the old way
(Limits). A migration you wrote by hand (a seed) is not copied:
write it again for the new engine, and until then migrate stops at its
number and names the file.
A server environment needs more than the address (fieldops also wants
GLOBETROTTER_FILE_SECRET): see
what a server refuses to start without.
Treat Rust on mysql and any part fieldops does not use as untested
against a live server until you have run the suite on yours: serve the backend on a copy of your database
(GLOBETROTTER_<STORE>_URL) and run uv run pytest with
GLOBETROTTER_TEST_BASE_URL set to it. The tests then write made-up rows into
the database they press. The Rust target's crate compiles for all three
and reads the rows the Python backend wrote. mongodb and duckdb are in the
catalogue's list of engines but neither target runs them; redis is a cache
store only.
Engine differences the design knows about:
- A
stringwith nomaxholds 255 characters:VARCHAR(255)on postgres and mysql, and sqlite'sTEXTheld to the same by the rules.textis the long type,TEXTeverywhere, no length unless it says one. Neither takes a NUL. The contract says both, and a value past them is a 400 (The email takes at most 255 characters.,The name is not text without a NUL character.: transcript). - A uuid is
UUIDon postgres,TEXTon sqlite andCHAR(32)on mysql, holding 32 hex digits (as SQLAlchemy's Uuid and the Rust target write it; an older mysql table'sCHAR(36)still fits). In JSON it is hyphenated. The audit, outbox and flow-run ids are hyphenated text (CHAR(36)). - A no-overlap index is an EXCLUDE constraint on postgres (half open,
btree_gist) and two triggers on sqlite; mysql does not keep it. - A link (a relation's foreign key) is a
REFERENCESon its column on postgres and sqlite. mysql ignores that, so there it is a named constraint of the table,CONSTRAINT <table>_<column>_fkey FOREIGN KEY …: inCREATE TABLEwhen the table it points at exists, else added after every table (a cycle);ADD CONSTRAINTwith a link column added later;DROP FOREIGN KEYbefore one is dropped or itsonDeletechanges. Written, not run on mysql. - mysql migrations written before 2026-11-13 put links on the column, so
such a store has no working foreign keys. Written files are never rewritten.
globetrotter syncsays it, one line per store, and writesbackend/migrations/<store>/mysql-foreign-keys.sql: the statements that add every link still owed as a named constraint, join tables too. Its first lines say how to find rows that name a row that is not there; each statement fails on one. Fix those rows, then copy the file into your next mysql migration (the line names it,mysql/<next>_foreign_keys.sql). Sync is quiet only when the store's mysql migrations hold every constraint it owes, by name (<table>_<column>_fkey); until then it names the ones still lacking. The file is a stub (@stub-hashin its first lines): untouched, each sync rewrites it to what is still owed, so copying part of it into a migration leaves the rest in it. Edited by hand it is yours: sync keeps it as it is and says so. When nothing is owed sync says it is no longer needed and leaves it for you to remove. It is not a numbered migration because a number belongs to every engine of the store, and no runner reads it.sync --checksays the line and writes nothing;globetrotter status,service_statusand the studio's Status list the keys as due. Tested as text; never run on mysql. - sqlite cannot change a column's type in place. Within one storage (string,
text, uuid, date, json: all TEXT) the file says it keeps the column. Across
storage (text to int, a boolean to a string) the file makes it: the table is
rebuilt where nothing points at it, else the column is added again, copied
across with a
CAST, the old one dropped and the new one renamed; a column that is unique or indexed cannot be, and the file and sync carry aWARNINGthat sqlite did NOT change it (written; the rebuild by hand). - A key's kind (uuid to int, string...) or an entity's
idKindfamily cannot change once the entity has a table: the save is refused at once andsyncwrites nothing for the target (a!line;sync --checkfails), with what to do: a new entity and a copy, or, with no data yet, deletebackend/migrations/<store>/anddesigns/.memory/synced/<design>.<store>.*.jsonand sync afresh. - Making a relation Always, or taking it off, is a migration step with a
NOTE(sqlite gets a rebuild recipe). - On sqlite the app, the relay and a worker write one file: it runs in WAL with a 30 second busy wait, and a run's end is tried again when the file is busy.
A store is named in globetrotter.config.json and components.<env>.json; a
components file may swap an engine within a family (sqlite on a laptop for
postgres in production). Several stores may be in one design; each has its own
migrations.
Sample rows
Migrating never adds sample rows to a new project. Sample rows are a separate step, from the backend's folder:
$ GLOBETROTTER_ENV=local uv run python -m <app>_core.migrate --seed [store]
db: seeded 0001_demo.sqlIt runs backend/seed/<store>/<engine>/*.sql in name order, each file once (its
name is kept in the table globetrotter_seed), each in one transaction. Without
GLOBETROTTER_ENV=local it refuses and says so; --force allows another
non-production environment (a stage database), never another environment's
database. Each database is marked with the environment it was first migrated
for (table globetrotter_meta). A database marked production, or for any name
other than local, stage, staging, test, testing, qa, preview, dev, development,
demo or sandbox, is refused from every shell with or without --force; so is a
database marked for an environment other than the shell's, and so is a shell that
says production, even on an unmarked database. Nothing changes a mark: a wrong
one is corrected in SQL, by a person.
Sync never writes or deletes anything in seed/: it is yours. Pressed on Postgres
and sqlite for every mark and shell: transcript.
A file is plain SQL for the store's engine. A row of a table the design made
needs the two columns sync adds beside the fields, created_at and
updated_at (see the CREATE TABLE in the migration). For the quickstart's
note table, backend/seed/db/sqlite/0001_demo.sql:
insert into note (id, text, created_at, updated_at)
values ('00000000000000000000000000000001', 'seeded', '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z');On sqlite a time may be written with a T and an offset, as here, or as the
app writes it (2026-01-01 00:00:00.000000): lists filter, order and page
rows of both forms by the instant (Limits).
$ GLOBETROTTER_ENV=local uv run python -m my_api_core.migrate --seed
db: seeded 0001_demo.sql
$ GLOBETROTTER_ENV=local uv run python -m my_api_core.migrate --seed
db: already seeded, nothing to applyA row the database refuses stops with one sentence and a non-zero exit, no
traceback, and keeps nothing of that file: Seeding stopped: seed/db/sqlite/0001_demo.sql was refused while inserting into note (NOT NULL constraint failed: note.created_at); none of its rows were kept. It adds which column a seed must
name when the database says so (the migration gives created_at and
updated_at no default). With no files it says where to put them. Without
GLOBETROTTER_ENV=local it says Seeding writes sample rows: it runs only with GLOBETROTTER_ENV=local (it is stage). To seed this stage database on purpose, add --force. (the shell's own word where it says stage).
The three examples were made before this and keep their 0002_seed.sql in the
migration chain. It is already applied in their databases, so it is not
renumbered or rewritten; a new database of theirs still gets the rows by
migrating. A new project puts its rows in seed/ instead. Nothing starts the
seed for you yet: run it after migrate on a laptop.
Connection pools and timeouts
On postgres and mysql each store's engine has a bounded pool that checks a
connection before handing it out and renews old ones, and a longest run for one
statement. The variables are per store (GLOBETROTTER_<STORE>_<NAME>, the store
as in GLOBETROTTER_<STORE>_URL), else for every store (GLOBETROTTER_DB_<NAME>):
<NAME> |
Meaning | Default |
|---|---|---|
POOL_SIZE |
connections kept | 10 |
MAX_OVERFLOW |
more, while all are busy | 10 |
POOL_TIMEOUT |
seconds a request waits for one | 30 |
POOL_RECYCLE |
seconds before a connection is renewed | 1800 |
STATEMENT_TIMEOUT_MS |
a statement's longest run, 0 for none | 30000 |
The timeout is statement_timeout on postgres and max_execution_time on
MySQL (max_statement_time on MariaDB). Pre-ping is always on. sqlite keeps WAL
and a 30 second busy wait. These are set in observe.py, so they apply when the
design has an observability section and the process runs observe.configure()
(GLOBETROTTER_OBSERVE=off keeps the pool tuning on, and turns the rest off). Not yet run against a
real postgres or mysql here.
Lists are bounded
A list the service reads for you answers at most GLOBETROTTER_LIST_DEFAULT
rows (50) when it has no page size, and never more than GLOBETROTTER_LIST_MAX
(200), whatever size was asked for. Give a list paging: page or
paging: cursor (reference; the Pagination block adds
page and size params) to reach the rest. A list with no paging is cut at 50:
it answers X-Truncated: true when it uses any of the query vocabulary (a
sort, a filter, …), and says nothing when it uses none. A find in your own code is bounded too:
ctx.db.job.find() with no limit= answers the first 50 rows and logs a
warning naming the line when there were more; find(unbounded=True) reads every
row (on Rust, Find::unbounded(), and limit: Some(n) for a number).
Metrics
With GLOBETROTTER_METRICS=1 and observability.metrics on in the design,
GET /metrics answers in Prometheus' text format: http_requests_total and
http_request_duration_seconds by method, route template and status, and
globetrotter_db_pool_size, _checked_out and _overflow by store. Set
GLOBETROTTER_METRICS_TOKEN and it needs Authorization: Bearer <token>.
Each process counts its own requests: with several workers, scrape each. Keep the path
on the internal network.
Back up and restore
python -m <app>_core.data in backend/:
$ uv run python -m <app>_core.data backup
$ uv run python -m <app>_core.data restore backups/<file>.sqliteBackup copies a store while it serves, into backups/<store>-<time>.sqlite,
and says its migration and its rows by table. On sqlite it goes through
sqlite's own backup, because a plain cp db.sqlite misses what still sits in
db.sqlite-wal: in one test the copy held 4 of 10 jobs and none of 12 audit
rows. On postgres or mysql it says the pg_dump or mysqldump to run. Every
table comes along: audit_log, the outbox and alembic_version included.
Restore puts a file back through sqlite (copying an older file over the
store while a -wal sits beside it corrupted it). It keeps the store as it was
beside it first, and says what this code needs against what the copy holds.
Stop the API, the relay and the workers first. Each restore keeps the store it
replaces under a name of its own.
After a bad migration, deploy the code the backup was taken with before
anything else: /ready names a waiting migration's DESTRUCTIVE line so nobody
reruns it on the restored rows.
What a restore costs:
- Rows written after the backup are gone, with their audit rows.
- Events the outbox held then are handed on when the relay runs.
- One the worker had already run after the backup runs again, every step of it,
so a receipt is e-mailed twice. The restore names these by the store it
replaces (
3 events waiting in the backup the worker has run since: order.placed NB-1042, …). --keep-donekeeps them done so they do not run again. What their steps wrote in the store is gone either way: it was written after the backup.
Export and import
$ uv run python -m <app>_core.data export job # CSV; --json for JSON lines
$ uv run python -m <app>_core.data import job customers.csvExport writes an entity's rows with the fields as the contract spells them. Import reads them back through the design's rules, references and unique columns:
- Every refused row is said by its line, with the value the file gave:
line 38 (id c37): The priority is one of Low, Normal, Urgent. (the file says 'urgent'). - Nothing is written unless every row passes.
--skip-refusedtakes the rest;--dry-runwrites nothing. - Each row lands in the audit as
import customers.csv.
A page's create is not an import: it takes the form's fields, not the entity's, and its body does what a person's press means. Fieldops' create makes a job per press, due two days later, and deletes none.
Next: Flows and jobs, Deploy and operate, Limits.