Skip to content

CI: migration:run dry-run (added in #1070) can't pass — no baseline schema migration #1193

Description

@RUKAYAT-CODER

Summary

The validate job's Run migrations step (pnpm run migration:run against a fresh Postgres, added by #1070) has never passed and blocks validate for every PR, independently of the code under test.

Root cause

The migrations in src/migrations/ are incremental patches authored on top of a schema that TypeORM creates via synchronize in dev (getDatabaseConfig() sets synchronize: process.env.NODE_ENV !== 'production'). There is no baseline migration that creates the core tables (users, courses, …).

On an empty CI database the run therefore fails immediately:

QueryFailedError: relation "users" does not exist
  at CreateMessageTable1630000000000.up
  query: ALTER TABLE "messages" ADD CONSTRAINT "FK_..." FOREIGN KEY ("senderId") REFERENCES "users"("id") ...

The very first migration assumes users already exists, so migration:run from scratch cannot succeed with the current migration set.

Timeline

What's already been fixed (see PR #1192)

Two prerequisites that were also broken have been resolved on the way to reproducing this cleanly:

  • Migrations glob in src/config/datasource.ts narrowed to src/migrations/[0-9]*.{ts,js} so schema-migration.service.ts and entities/migration.entity.ts are no longer loaded as migrations (this matches the migration:generate:check script's own find ... -name '[0-9]*.ts' convention). Renamed AddTimezoneLocalePreferences.ts1710000000000-AddTimezoneLocalePreferences.ts.
  • Added 1600000000000-enable-uuid-ossp.ts (CREATE EXTENSION IF NOT EXISTS "uuid-ossp") so migrations that default ids to uuid_generate_v4() work on a fresh DB.

With those in place, migration:run now progresses to the missing-baseline failure above.

Options to resolve (decision needed)

  1. Author a baseline schema migration (lowest timestamp) generated from the current entities so migration:run builds the full schema from scratch, ensuring the existing incremental migrations still apply cleanly on top. Needs a live DB and careful verification against the drift check.
  2. Bootstrap the schema before the dry-run in CI (e.g. create it via synchronize from entities, then run migrations) — changes the intent of the from-scratch dry-run.
  3. Relax/remove the from-scratch migration:run/migration:revert/drift-check steps introduced in Add automated database migration dry-run step to CI pipeline #1070 until a baseline exists.

Acceptance criteria

  • validate (lint:citypecheckbuildmigration:run → drift check → migration:revert) passes on a fresh Postgres.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions