Repository navigation
Add TypeORM database migrations and disable synchronize in production #165
Copy link
Copy link
Closed
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignCampaign: Third CampaignbackendBackend related issuesBackend related issuesdatabaseDatabase and migrationsDatabase and migrationsdifficulty:hardHard difficulty issuesHard difficulty issuespriority:highHigh priority issuesHigh priority issues
Description
What
Generate initial TypeORM migrations from the current entity definitions, add a migration generation script, and ensure synchronize: false in production configuration with explicit migration execution on startup.
Why
The backend uses TypeORM with synchronize: true which auto-creates/alters database tables on every startup. This is fine for development but catastrophic in production — it can drop columns, lose data, or cause downtime during schema changes. The deploy script references npm run typeorm migration:run but no migration files exist. A proper migration workflow is essential before any production deployment.
Scope
In scope:
- Generate initial migration from current entity definitions (
npm run typeorm migration:generate) - Add migration scripts to
package.json:migration:generate,migration:run,migration:revert - Configure TypeORM to use
synchronize: trueonly in development,falsein production - Add migration execution to the application bootstrap (run pending migrations on startup)
- Create a
data-source.tsfile for TypeORM CLI configuration
Out of scope:
- Changing entity definitions
- Adding new entities
- Database seeding (separate issue)
- Multi-database support
Acceptance Criteria
- Initial migration file exists in
backend/src/migrations/ -
npm run migration:generatecreates a new migration from entity changes -
npm run migration:runapplies all pending migrations -
npm run migration:revertreverts the last migration -
synchronizeistrueonly whenNODE_ENV=development - Application runs migrations on startup in production mode
-
data-source.tsexists for TypeORM CLI usage
Technical Context
- TypeORM config:
backend/src/app.module.ts(TypeOrmModule.forRoot) - Entities are auto-discovered via
autoLoadEntities: true - TypeORM migration docs: https://typeorm.io/migrations
- Deploy script:
scripts/deploy-backend.shreferencesnpm run typeorm migration:run - Create
backend/src/data-source.tsfor CLI:npx typeorm -d src/data-source.ts migration:generate
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignCampaign: Third CampaignbackendBackend related issuesBackend related issuesdatabaseDatabase and migrationsDatabase and migrationsdifficulty:hardHard difficulty issuesHard difficulty issuespriority:highHigh priority issuesHigh priority issues
Activity
koder-ns commentedon Aug 23, 2026
please can i work on this
GauravKarakoti commentedon Aug 23, 2026
Allow me to work on this one
meshackyaro commentedon Aug 23, 2026
Hi maintainer, I am submitting my application to set up the TypeORM migration workflow and eliminate
synchronize: truefor production environments.Approach & Technical Implementation
1. CLI Data Source Setup (
data-source.ts)backend/src/data-source.tsexporting a dedicatedDataSourceinstance for the TypeORM CLI. It will read database credentials directly from environment variables (process.env) to support CLI commands liketypeorm migration:generate.src/entities/**/*.tsor explicit imports) and migration output paths (src/migrations/*.ts) so generated migrations are automatically picked up and placed inbackend/src/migrations/.2. AppModule & Bootstrap Integration
synchronize: UpdateTypeOrmModule.forRootAsyncinapp.module.tsto ensuresynchronizeevaluates strictly toprocess.env.NODE_ENV === 'development'.migrationsRun: truein the production TypeORM options (or explicitly executedataSource.runMigrations()insidebackend/src/main.tsprior toapp.listen()) so pending schema updates execute reliably on container/app startup before accepting traffic.3. NPM Scripts & Workflow
package.jsonreferencing the newdata-source.ts:Execution Plan
backend/src/data-source.ts, verify database connection via CLI, and generate the baselineInitialSchemamigration capturing the current state of all entities.app.module.tsto togglesynchronizebased onNODE_ENVand enable automatic startup migration execution for non-development environments.migration:generate,migration:run, andmigration:revertinpackage.json.migration:runandmigration:revertagainst a clean test database.npm run start:prodexecutes pending migrations on startup withsynchronize: false.scripts/deploy-backend.sh.Ready to pick this up as soon as assigned!
grantfox-oss commentedon Aug 23, 2026
🦊 GrantFox — @meshackyaro has been assigned to this issue as part of the Third Campaign campaign!
Next steps:
Closes #165)Good luck! Track your progress on GrantFox.
grantfox-oss commentedon Aug 24, 2026
🎉 This issue has been marked as completed on GrantFox as part of the Third Campaign campaign!
@meshackyaro's PR #175 was approved and merged by @Josie123-Dev.
🏆 @meshackyaro: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (605 total points). Track your full progress on GrantFox.
👏 Great work, @meshackyaro! Keep contributing to GuardZero144.