refactor(db): auto-generate migration registry (closes #24) #25
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/proper-db"
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?
Closes #24.
Summary
The two call sites that knew the migration list —
nexus/src/lib/server/db/migrate.tsandnexus/src/lib/server/testing/db.ts— now both consumemigrations.generated.ts, written bynexus/scripts/gen-migrations.mjsfrom areaddirofnexus/migrations/. Adding a migration is now just dropping the file.Why not switch to Drizzle (despite the issue title)
Independent research turned up that Drizzle has the same constraint under bundled deployment: its own docs prescribe a generated index module fed through Babel's
inline-importplugin, so the registry doesn't disappear — it just changes shape. Meanwhile Kysely has the stronger type-safety story for our strict-mode +noUncheckedIndexedAccesssetup, and there is no Kysely → Drizzle codemod, so a swap would mean rewriting every query call site for zero ergonomic gain.Sources consulted (June 2025 marmelab comparison, April 2025 DEV piece, Kysely issue #23, Drizzle Expo SQLite guide) all point at codegen as the right minimal fix.
What's in this PR
nexus/scripts/gen-migrations.mjs— scansnexus/migrations/*.ts, emitsmigrations.generated.tswith aRecord<string, Migration>. Idempotent: skips writing when content is unchanged.nexus/src/lib/server/db/migrate.ts— imports the generated registry; the inline list is gone.nexus/src/lib/server/testing/db.ts— same, plus the sequentialawait up0001(db); …chain is replaced byfor (const m of Object.values(migrations)) await m.up(db).vite.config.tsandvitest.config.tsat top-level (coverspnpm dev,vite build, andpnpm test), and prepended tobuild:serverinpackage.jsonfor the esbuild path..gitignoreignores the generated file.Test plan
pnpm typecheck— 842 files, 0 errorspnpm test— 47 files, 474 tests, all greenpnpm run build:server— deleted the generated file first; codegen regenerated it and esbuild producedbuild/server.js(59.7 kb)docker compose up -dand confirm migrations apply on a fresh data volume