3.0 KiB
3.0 KiB
Implementation Plan: Register SeedSampleChallenges migration in DatabaseModule
1. Architectural Reconnaissance
- Codebase style & conventions: NestJS + TypeORM; migrations are registered manually via an in-source
MIGRATIONSarray (not a filesystem glob) inbackend/src/database/database.module.ts. Imports follow chronological order matching the array. - Data Layer: SQLite via
better-sqlite3.DatabaseInitService.init()(called frommain.tsbeforeapp.listen()) executesdataSource.runMigrations({ transaction: 'each' }), which uses theMIGRATIONSarray registered withTypeOrmModule.forRootAsync. Until the array contains the new class,npm run setupand the first app boot will not runSeedSampleChallenges1700000000600. - Test framework: Jest; backend tests construct their own in-memory
DataSourcewith an explicitmigrations: [...]list — they bypassDatabaseModule, which is whymigrations.spec.ts(already updated for Job 906) passes despite this gap. - Required tools & dependencies: none.
2. Impacted Files
- To Modify:
backend/src/database/database.module.ts— add the import and append the new migration class to theMIGRATIONSarray, right afterUpgradeChallengeAdminSchema1700000000500.
3. Proposed Changes
- Edit
database.module.ts:- Add the import alongside the other chronological migration imports (between
.../1700000000500-UpgradeChallengeAdminSchemaand the next non-migration importDatabaseInitService):import { SeedSampleChallenges1700000000600 } from './migrations/1700000000600-SeedSampleChallenges'; - Append to the
MIGRATIONSarray, immediately afterUpgradeChallengeAdminSchema1700000000500:SeedSampleChallenges1700000000600,
- Add the import alongside the other chronological migration imports (between
- No other code changes. The migration class already exists, is exported, and is covered by tests in
tests/backend/migrations.spec.ts. Once registered in the TypeORMMIGRATIONSarray,DatabaseInitService.init()(called viamain.tsand indirectly bynpm run setup) will execute it on next boot. - Verification expectation: After
npm run setup(or first boot on a fresh DB),SELECT COUNT(*) FROM challenge;returns> 0and the eight sample names are present. Re-running setup on a DB that already has rows is a no-op (the migration's early-return guard).
4. Test Strategy
- No new automated tests required. The existing
tests/backend/migrations.spec.tsalready asserts the seed runs and that values are schema-compatible, schema-correct, anddown()is scoped correctly. The fix is purely a wiring change that registers an already-tested class with the productionDatabaseModule, which has no dedicated test (and per the Jobs rule, no new test files should be introduced for a 2-line wiring fix). - Manual smoke (tester steps, no UI): on a fresh DB file, run
npm run setupthensqlite3 ./data/db.sqlite 'SELECT COUNT(*) FROM challenge;'and confirm the count is8; on a re-run, confirm the count is unchanged (idempotent guard works).