fix(api): disable synchronize:true in all environments#216
Conversation
Replace TypeORM synchronize:true (dev/test) with synchronize:false and migrationsRun:true in all environments. This ensures missing CREATE TABLE migrations surface immediately during development instead of only failing on staging deploys. - Set synchronize: false, migrationsRun: true in app.module.ts - Add migrations glob path so TypeORM finds migration files - Add migrate:dev convenience script to package.json - Update DATABASE_EVOLUTION_PROTOCOL.md environment behavior matrix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 2409dd078846
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughDisables TypeORM's automatic schema sync and enables running explicit migrations on startup (migrationsRun: true). Adds a developer npm script to run migrations and updates documentation and project planning state to reflect the migration-first workflow. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App as "Application\n(startup)"
participant TypeORM as "TypeORM\nMigration Runner"
participant DB as "Database"
App->>TypeORM: initialize TypeOrmModule (migrationsRun: true)
Note right of TypeORM: load migrations from\n`dist/migrations/*.js`
TypeORM->>DB: connect
TypeORM->>DB: run pending migrations
DB-->>TypeORM: migration results
TypeORM-->>App: startup completes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/DATABASE_EVOLUTION_PROTOCOL.md (1)
341-341:⚠️ Potential issue | 🟡 MinorMinor: Incorrect line reference.
The reference states "lines 83-85 for
synchronizesetting" but in the updatedapp.module.ts, the synchronize/migrations/migrationsRun settings are at lines 85-87.📝 Suggested fix
-- **TypeORM config:** `apps/api/src/app.module.ts` (lines 83-85 for `synchronize` setting) +- **TypeORM config:** `apps/api/src/app.module.ts` (lines 85-87 for `synchronize` setting)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/DATABASE_EVOLUTION_PROTOCOL.md` at line 341, Update the line reference in docs/DATABASE_EVOLUTION_PROTOCOL.md: change the mention of "lines 83-85 for `synchronize` setting" to the correct lines (where `synchronize`, `migrations`, and `migrationsRun` are currently located) by referencing the `apps/api/src/app.module.ts` block that contains the TypeORM config (the `synchronize`, `migrations`, and `migrationsRun` settings) so the doc points to the correct lines.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@docs/DATABASE_EVOLUTION_PROTOCOL.md`:
- Line 341: Update the line reference in docs/DATABASE_EVOLUTION_PROTOCOL.md:
change the mention of "lines 83-85 for `synchronize` setting" to the correct
lines (where `synchronize`, `migrations`, and `migrationsRun` are currently
located) by referencing the `apps/api/src/app.module.ts` block that contains the
TypeORM config (the `synchronize`, `migrations`, and `migrationsRun` settings)
so the doc points to the correct lines.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.planning/STATE.md.planning/todos/done/2026-02-22-disable-synchronize-true-all-envs.mdapps/api/package.jsonapps/api/src/app.module.tsdocs/DATABASE_EVOLUTION_PROTOCOL.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 47b65ee5080c
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/DATABASE_EVOLUTION_PROTOCOL.md (1)
341-341: Consider removing hardcoded line numbers for maintainability.The reference includes specific line numbers
(lines 85-87)which will become stale asapp.module.tsevolves. Consider using a more general reference such as:- **TypeORM config:** `apps/api/src/app.module.ts` (TypeORM configuration block for `synchronize`/`migrations`/`migrationsRun`)This maintains clarity while reducing maintenance burden.
♻️ Proposed refactor
-- **TypeORM config:** `apps/api/src/app.module.ts` (lines 85-87 for `synchronize`/`migrations`/`migrationsRun`) +- **TypeORM config:** `apps/api/src/app.module.ts` (TypeORM configuration block for `synchronize`/`migrations`/`migrationsRun`)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/DATABASE_EVOLUTION_PROTOCOL.md` at line 341, Remove the hardcoded line-number reference in the TypeORM config callout and instead point readers to the TypeORM configuration block in apps/api/src/app.module.ts; update the line to something like "`apps/api/src/app.module.ts` (TypeORM configuration block for `synchronize`/`migrations`/`migrationsRun`)" so the reference remains accurate as app.module.ts changes and still highlights the `synchronize`, `migrations`, and `migrationsRun` settings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/DATABASE_EVOLUTION_PROTOCOL.md`:
- Line 341: Remove the hardcoded line-number reference in the TypeORM config
callout and instead point readers to the TypeORM configuration block in
apps/api/src/app.module.ts; update the line to something like
"`apps/api/src/app.module.ts` (TypeORM configuration block for
`synchronize`/`migrations`/`migrationsRun`)" so the reference remains accurate
as app.module.ts changes and still highlights the `synchronize`, `migrations`,
and `migrationsRun` settings.
Track idea to add a CI job that runs typeorm migration:generate against a fresh database to detect entity-vs-migration drift automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 1f923be1abe1
Summary
synchronize: falsein all environments (wastruefor dev/test)migrationsRun: trueso migrations auto-run on app start, replacing the auto-sync behaviormigrationsglob path to TypeORM config so it finds migration filesmigrate:devconvenience script topackage.jsonDATABASE_EVOLUTION_PROTOCOL.mdenvironment behavior matrix and related sectionsContext
synchronize: truein dev/test masked missingCREATE TABLEmigrations — tables were auto-created from entity decorators, so missing migrations only surfaced on staging deploys. This caused the Phase 14 staging failure (PR #186).With this change, the dev server fails immediately if a new entity lacks a migration, catching the gap at development time.
All 13 entities verified to have corresponding
CREATE TABLEmigrations — no gaps exist.Test plan
pnpm --filter api build)pnpm --filter api test)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
migrate:devnpm script to run database migrations in development.Documentation
synchronizeis disabled everywhere, and migrations now run automatically on startup (missing migrations surface at startup).Chores