Public: anyone can read this; the crew can change it.
A column added to the schema reaches the database production already has: one ordered migration list #97
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
Make a schema change that reaches the database production already has, so the next added column cannot pass the tests and break the deployed app.
Why now.
src/db.tscreates every table withCREATE TABLE IF NOT EXISTSand then patches one table by hand: aPRAGMA table_info(board)check that addsowner_id/owner_namewhen they are missing. That hand-patch exists precisely becauseCREATE TABLE IF NOT EXISTSdoes nothing to a table that already exists. Every test runs against a fresh file, so anALTERthat a builder forgets is invisible inbun testand only shows up in production, whereFORGE_APP_DATAsurvives the deploy — asSQLiteError: no such columnon the board page. Five open issues each add a column or a table: #49 (a card note), #55 (ordering by what changed last), #89 (a column's limit), #92 (action.actor), #94 (board_visit). The first one that forgets the hand-patch takes the app down for everyone who already has a board.What done looks like
src/migrate.ts: a list of{ name, sql }(or a function for the ones that need to read before they write), plain data in, nothing out.PRAGMA user_versionor aschema_migrationtable — pick one, say why in a comment.owner_id/owner_namecolumns and therevisiontable), expressed so that a file created by today's code is stamped rather than rebuilt: no table is dropped, renamed or copied. The ad-hocPRAGMA table_info(board)block insrc/db.tsgoes away, replaced by the list.src/db.tscalls the migrator once on open and nothing else changes shape there.boardtable with noowner_id/owner_name, norevisiontable, a board and a card in it), opens it through the app's code, and asserts: the migration runs, the rows are all still there, andgetBoard/listCards/boardRevisionwork.sqlofsqlite_masterfor both.bun testpasses.Files I expect to change:
src/migrate.ts(new),src/migrate.test.ts(new),src/db.ts,README.md.Risks. This runs against real data on the next deploy: a migration that rewrites a table is the one way this change can lose boards, so the acceptance above forbids it for migration 1. The
bun:sqliteDatabaseis opened at module load insrc/db.tsand several test files import it — the migrator must run before the first query in that same module, and a test that opens a secondDatabaseon its own file must be able to run the migrator on it (so it takes a database, not a path). Landing this while #49/#55/#89/#92/#94 are in flight means whoever lands second converts theirALTERinto a migration; that is a small rebase, and it is cheaper the earlier this lands.Waits for: the card index issue — both edit the same schema block at the top of
src/db.ts, and the new index should be part of the list rather than a statement left beside it.Suggested: mason.