Summary
Schema management currently leans on TypeORMs synchronize flag, driven entirely by config (backend/src/config/database.config.ts, consumed in app.module.ts). There is no migrations/ directory and no migration workflow beyond the generic typeorm CLI script. Nothing prevents DB_SYNCHRONIZE=true from reaching production, where auto-sync can alter or drop columns with data loss. With 17 entities already across users, puzzles, streak, quests, analytics, game-sessions, and challenge-attempt, schema drift is the top operational risk.
Proposal
- Add
backend/src/database/migrations/; extract a reusable data-source factory out of the inline useFactory in app.module.ts so the CLI and the app share one config.
- Wire npm scripts:
migration:run, migration:revert, migration:generate.
- Enforce safety: fail fast at boot when
NODE_ENV=production && synchronize=true.
- Document the flow in
docs/DEVELOPMENT.md.
Acceptance criteria
Summary
Schema management currently leans on TypeORMs
synchronizeflag, driven entirely by config (backend/src/config/database.config.ts, consumed inapp.module.ts). There is nomigrations/directory and no migration workflow beyond the generictypeormCLI script. Nothing preventsDB_SYNCHRONIZE=truefrom reaching production, where auto-sync can alter or drop columns with data loss. With 17 entities already acrossusers,puzzles,streak,quests,analytics,game-sessions, andchallenge-attempt, schema drift is the top operational risk.Proposal
backend/src/database/migrations/; extract a reusabledata-sourcefactory out of the inlineuseFactoryinapp.module.tsso the CLI and the app share one config.migration:run,migration:revert,migration:generate.NODE_ENV=production && synchronize=true.docs/DEVELOPMENT.md.Acceptance criteria
migration:run.