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 runningpg_dumpitself 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 asapp.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 TABLEconstraints, 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.COPYis 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 restart (#15266): a running app holds the file it opened at start, and the import
renames a new one over it, so once the file is in place an import or an undo deploys production
again at its own commit, the same
redeploythe app page's button asks for (restartAfterMove,src/actions/migrate_data.ts). Only a running (or coming-up) production is restarted; one asleep or stopped opens the new file when it next starts, so nothing in flight is dropped for it. The result line, the API's and MCP'srestart(restarted,asleep,not_running) and the terminal say which.
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;dumpis a dry run;apply/undoneed an admin-scope token. - Terminal: the "Move the data" screen (
src/tui/screens/datamove.ts):mchecks a drop file,aimports it,uundoes after a y/n.
Not done
- 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.