Overview
AppModule sets synchronize: true in the TypeORM config, which automatically alters the database schema on every app start. This can silently drop columns on any non-local environment and is explicitly unsafe for production by the TypeORM docs.
Context
- TypeORM config:
backend/src/app.module.ts — synchronize: true on line ~85
- All entity files are in
backend/src/*/entities/
- TypeORM CLI uses a separate
DataSource config file pointing to entity paths
Tasks
Files to Modify / Create
backend/src/app.module.ts
- New:
backend/src/data-source.ts
- New:
backend/src/migrations/ (generated migration file)
backend/package.json
Overview
AppModulesetssynchronize: truein the TypeORM config, which automatically alters the database schema on every app start. This can silently drop columns on any non-local environment and is explicitly unsafe for production by the TypeORM docs.Context
backend/src/app.module.ts—synchronize: trueon line ~85backend/src/*/entities/DataSourceconfig file pointing to entity pathsTasks
synchronize: falseinTypeOrmModule.forRootAsync()config for all environmentsbackend/src/data-source.tsas the TypeORM CLI data source file:.envviadotenvmigrationstosrc/migrations/**/*.tsbackend/package.json:"migration:generate": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:generate -d src/data-source.ts""migration:run": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:run -d src/data-source.ts""migration:revert": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli migration:revert -d src/data-source.ts"npm run migration:generate -- src/migrations/InitialSchemanpm run migration:run.env.examplethat migrations must be run manually after deploymentFiles to Modify / Create
backend/src/app.module.tsbackend/src/data-source.tsbackend/src/migrations/(generated migration file)backend/package.json