Skip to content

Comments

feat(database): add TypeORM migration support#469

Merged
cre8 merged 6 commits intomainfrom
feat/typeorm-migrations
Feb 19, 2026
Merged

feat(database): add TypeORM migration support#469
cre8 merged 6 commits intomainfrom
feat/typeorm-migrations

Conversation

@cre8
Copy link
Contributor

@cre8 cre8 commented Feb 19, 2026

Summary

Add TypeORM migration support to enable safe database schema upgrades for existing installations.

Breaking Change

Schema synchronization (synchronize: true) is now disabled by default. Use migrations instead for production safety.

Changes

New Files

  • apps/backend/src/database/data-source.ts - TypeORM CLI datasource configuration
  • apps/backend/src/database/migrations/1740000000000-BaselineMigration.ts - Baseline migration capturing current schema
  • apps/backend/src/database/migrations/README.md - Migration workflow documentation

Modified Files

  • apps/backend/src/database/database.module.ts - Added migration configuration and startup warning for pending migrations
  • apps/backend/src/database/database-validation.schema.ts - Added DB_SYNCHRONIZE and DB_MIGRATIONS_RUN options
  • apps/backend/package.json - Added migration CLI scripts
  • .env.example and deployment env files - Documented new configuration options
  • docs/architecture/database.md - Added migrations documentation section

New Configuration Options

Variable Default Description
DB_MIGRATIONS_RUN true Run pending migrations automatically on startup
DB_SYNCHRONIZE false Enable TypeORM schema sync (⚠️ dev only)

Migration Commands

# From apps/backend directory
pnpm migration:generate --name=AddNewFeature  # Generate migration from entity changes
pnpm migration:run                             # Run pending migrations
pnpm migration:revert                          # Revert last migration
pnpm migration:show                            # Show migration status

Upgrade Path

Existing installations will work automatically:

  1. The baseline migration detects if tables already exist
  2. If tables exist (from previous synchronize: true mode), creation is skipped
  3. All data is preserved, and the migration history starts fresh

No manual intervention required — just upgrade and restart.

@cre8 cre8 force-pushed the feat/typeorm-migrations branch from b2b75ec to 0e9f8b5 Compare February 19, 2026 08:35
@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.77%. Comparing base (7ec61cc) to head (d43810f).

Files with missing lines Patch % Lines
...base/migrations/1740000000000-BaselineMigration.ts 10.00% 8 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #469      +/-   ##
==========================================
- Coverage   55.79%   55.77%   -0.02%     
==========================================
  Files         164      165       +1     
  Lines        6010     6028      +18     
  Branches     1359     1358       -1     
==========================================
+ Hits         3353     3362       +9     
- Misses       2281     2289       +8     
- Partials      376      377       +1     
Flag Coverage Δ
e2e-test 55.77% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...backend/src/database/database-validation.schema.ts 100.00% <ø> (ø)
apps/backend/src/database/database.module.ts 100.00% <100.00%> (ø)
...base/migrations/1740000000000-BaselineMigration.ts 10.00% <10.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cre8 cre8 force-pushed the feat/typeorm-migrations branch from 5036ead to 0aeba40 Compare February 19, 2026 10:06
cre8 added 5 commits February 19, 2026 13:42
BREAKING CHANGE: Schema synchronization is now disabled by default.

- Add migration infrastructure with baseline migration for v2.0.0
- Disable synchronize by default (DB_SYNCHRONIZE=false)
- Enable auto-run migrations on startup (DB_MIGRATIONS_RUN=true)
- Add migration CLI scripts (generate, run, revert, show)
- Create data-source.ts for TypeORM CLI operations
- Update validation schema with new config options
- Document migration workflow in database.md

Existing databases are automatically detected - the baseline migration
skips table creation if tables already exist from synchronize mode.

Signed-off-by: Mirko Mollik <mirko.mollik@eudi.sprind.org>
- Remove complex schema creation from baseline migration
- Tests use synchronize=true, production uses migrations
- Baseline migration now just records itself without creating tables
- Avoids schema mismatch issues between migration SQL and entities

Signed-off-by: Mirko Mollik <mirko.mollik@eudi.sprind.org>
Signed-off-by: Mirko Mollik <mirko.mollik@eudi.sprind.org>
Signed-off-by: Mirko Mollik <mirko.mollik@eudi.sprind.org>
Fresh installations need synchronize=true to create the initial schema.
Production users can disable it after setup and rely on migrations.

Signed-off-by: Mirko Mollik <mirko.mollik@eudi.sprind.org>
@cre8 cre8 force-pushed the feat/typeorm-migrations branch from c20e47e to 0b9dedf Compare February 19, 2026 12:42
@sonarqubecloud
Copy link

@cre8 cre8 merged commit 909cf99 into main Feb 19, 2026
21 checks passed
@cre8 cre8 deleted the feat/typeorm-migrations branch February 19, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants