feat: adopt bchen-sqlite-migrate package; replace inline SCHEMA_DDL #9
Reference in New Issue
Block a user
Delete Branch "feat/adopt-sqlite-migrate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Phase 3 of the cross-project sqlite-migrate adoption — port nanodrop to consume
bchen-sqlite-migrate@v0.1.0(released at https://gitea.bchen.dev/brendan/sqlite-migrate). Replaces the inlinedb.exec(...)block insrc/db/schema.tswithapplyMigrations(db, MIGRATIONS_DIR, { genesisProbeTable: 'users' }).Follows buchinese PR #14 (merge_commit
19811d73…) and authd PR #15 (merge_commit0095f105…) structurally.Changes
package.json: +bchen-sqlite-migrategit+https dep pinned to#v0.1.0(resolves to commit7dbce663…); +db:migrate/db:status/db:stampnpm scripts.package-lock.json: regenerated from scratch withrm -rf node_modules package-lock.json && npm install --include=optional.src/db/migrations/0001_init.sql: NEW, captures currentinitDbDDL — 4 statements:users,files,login_attemptstables +idx_login_attempts_locked_untilindex.src/db/schema.ts: rewritten as thin wrapper aroundapplyMigrations; readsDB_MIGRATIONS_STAMP_GENESISenv var (optional, default-off — matches authd/buchinese behavior).src/scripts/{_db-cli,db-migrate,db-status,db-stamp}.ts: NEW operator CLIs, mirror authd/buchinese.tests/unit/migrations-byte-stable.test.ts: NEW, pinssha256(0001_init.sql) = 34f092b4bb8544a48acfee0fad08d51b1b75fedf4ffdfbcb790d2656d0f1d57aas the nanodrop-specific immutability guard.Security
None. Pure dep swap inside the server-side DB-init boundary. No new HTTP routes, auth gates, secrets, env-var leaks, or rate-limit-relevant surface.
MIGRATIONS_DIRis a compile-time constant (no traversal surface);applyMigrationsinvokesdb.execon trusted static repo content; the package'sFILENAME_REregex defeats path traversal at filename layer.db-stampreadsprocess.argv[2]but is an operator-only CLI (not web-reachable) andstampMigrationvalidates the version against a real file. Peer-depbetter-sqlite3already pinned at^12.6.2. Lockfile commit-SHA-pinned via#v0.1.0tag (resolves to commit7dbce663…).Environment
DB_MIGRATIONS_STAMP_GENESIS— optional, default-off. Read as=== '1'. Already declared as optional in authd/buchinese precedent; no deploy-manifest wiring needed (production nanodrop DBs already have all tables present, so genesis-stamp fires automatically via theusers-probe regardless of the env var). Setting it to1is only needed if a corrupted DB needs an explicit stamp without re-executing the genesis migration. No env-blocked gate triggered.Lockfile-verified
npm cion cleannode_modules(sandbox-side, exit 0).docker build .deferred to first prod deploy — docker daemon socket not reachable from sandbox (same caveat as authd PR #15 and buchinese PR #14).Tests
npm run build(tsc --noEmit) clean.npm testgreen: 131 passed across 19 files (was 130 + 1 new byte-stable test).initDb(':memory:'), exercising the cold-DB path throughapplyMigrationson every run.Expected first-deploy log
Production boot after this PR merges should show:
Subsequent boots:
migrations: 0 applied, 0 pending. If you seeCREATE TABLE … already existsinstead, the genesis probe is misconfigured — file a bug.Phase 3 of the cross-project sqlite-migrate adoption — port nanodrop to consume bchen-sqlite-migrate@v0.1.0. Replaces the inline db.exec(...) block in src/db/schema.ts with applyMigrations(db, MIGRATIONS_DIR, { genesisProbeTable: 'users' }). The genesis-probe (table 'users' exists) handles pre-existing prod DBs automatically — first deploy after merge stamps 0001_init as applied without re-executing, subsequent boots are no-ops. Adds three npm scripts (db:migrate, db:status, db:stamp) and a byte-stability test pinning sha256(0001_init.sql) so the migration is treated as immutable history.