Moving a platform app's data (#647)
A platform app's Postgres goes through the app's drop into the forge app's own store, with a
receipt, and can be taken back until a domain is cut over. It is the data line of the migration
checklist (docs/features/migration-mode.md); the engine under it is the database import in
docs/features/platform-app-move.md.
The path
- Make the dump where the old database is reachable. The page shows the one command
(EXPORT_COMMAND, src/apps/pg_dump.ts): pg_dump --inserts --no-owner --no-privileges
--no-comments "$DATABASE_URL" > dump.sql. The connection string stays on that machine; the forge
never receives it. (The forge running pg_dump itself with a connection string given once was
left out: it needs a Postgres client and an egress entry to a host the owner names.)
- Put it in the drop (
/<owner>/<name>/drop, up to 16 MB for an import). - Check, then import, at
/<owner>/<name>/data-move, reached from Import data on the app
page's migration card. Check does everything but put the file in place; Import first keeps the
store it replaces as app.db.before-import-<ms> (the snapshot), then replaces it.
- The receipt: per table the rows and SHA-256 on the dump's side and on the store's, and the
rows counted from the dump's own text. Import happens only when all agree. What a Postgres dump
has that SQLite has no meaning for (session SETs, set_config, setval, ownership,
column defaults, ALTER TABLE constraints, sequences, comments, extensions, schemas) is left out, counted, and
shown on the receipt. Primary, unique and foreign keys are not kept: the tables load without them, and the receipt says so; public. is dropped from names. COPY is refused: dump with --inserts.
Anything else the import's vetting refuses by statement number (SELECT, functions, UPDATE).
- Undo puts the snapshot back and sets the imported store aside as
app.db.undone-import-<ms>; nothing is deleted. When there was no store before, the imported one
is set aside and the app starts empty as it was. It is open until a domain of the app is verified
and has its old DNS recorded (the cut-over, app_domain.old_records); then an import and an undo
are both refused, since the old data is no longer the way back.
The record is the app.data_imported and app.data_undone events (the first carries the snapshot's
name and each table's rows and checksum): no state of its own.
Doors (all a repository admin's; anyone else gets not found)
- Page
/<owner>/<name>/data-move(GET, POSTdo=check|import|undo, same-origin checked). - API
GETandPOST /api/v1/repos/<owner>/<name>/data-move:{ dump }checks,{ dump, apply: true }
imports, { undo: true } undoes; an admin-scope token for POST.
- MCP
migrate_data { repo, dump?, apply?, undo? }: onlyrepoanswers the command, the drop's
dumps and the last receipt; dump is a dry run; apply/undo need an admin-scope token.
- Terminal: the "Move the data" screen (
src/tui/screens/datamove.ts):mchecks a drop file,
a imports it, u undoes after a y/n.
Not done
- The running app keeps its old file open until it restarts: restart it after an import or an undo.
- Only the store
app.dbin production; files and uploads arescripts/copy-app-files.ts. - Types are not translated: SQLite keeps the Postgres type names as declared and is loose about them.