Skip to content

fix(migrations): reconcile entity/migration drift so the schema drift check passes strictly - #1212

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Nimatstar:fix/1194-entity-migration-drift
Aug 17, 2026
Merged

fix(migrations): reconcile entity/migration drift so the schema drift check passes strictly#1212
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Nimatstar:fix/1194-entity-migration-drift

Conversation

@Nimatstar

Copy link
Copy Markdown
Contributor

Summary

Reconciles the pre-existing drift between the entity definitions and the schema produced by the migrations so migration:generate --check reports zero drift, then removes the scripts/known-drift.txt snapshot tolerance and makes the drift check strict again.

What changed

  • Entities aligned with the migration-produced schema
    • Added columns the migrations create but entities omitted: users localization fields (country, country_code, timezone, city, preferred_currency), user_preferences.currency, course.currency + canonical search_vector column, audit_logs.version, course_bulk_operations (undone_by_id, reason, notes, version).
    • Named entity indexes to match the explicit index names the migrations use (e.g. IDX_users_createdAt, IDX_course_category, IDX_audit_logs_*, grading/gamification/forum indexes) so no indexes are silently dropped.
    • Matched column types (timestamptz for audit/grading timestamps) and FK delete rules (messages, schema_change) to the migrations.
    • Kept the tier_enum type name on the gamification entities via enumName.
  • New reconciliation migration (1796000000000-reconcile-schema-drift) that creates the entity-declared indexes missing from the database, renames FK constraints to their entity-generated names, extends the audit_logs.action enum values, and backfills the missing course_bulk_operations columns.
  • Strict drift check: removed scripts/known-drift.txt and updated scripts/drift-check.sh to fail on any entity/migration drift.

Verification

  • pnpm run migration:run on a fresh Postgres ✔
  • pnpm run migration:generate:check → "No schema drift" ✔
  • pnpm run migration:revert
  • pnpm run lint:ci, pnpm run typecheck, pnpm run build

Closes #1194

…schema check

Align entity definitions with the schema produced by the migrations so
that migration:generate reports zero drift:

- Add columns to entities that migrations create but entities omit
  (users localization fields, user_preferences currency, course
  currency/search_vector, audit_logs version, course_bulk_operations
  undo/notes/reason/version).
- Name entity indexes to match the explicit index names the migrations
  use, and match column types (timestamptz) and FK delete rules.
- Register the course.search_vector generated column metadata.
- Add a reconciliation migration that aligns the remaining drift
  (indexes, FK constraint names, enum values, bulk-operation columns).
- Remove the known-drift snapshot and make drift-check.sh fail on any
  drift, so model changes without a migration are caught in CI.
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 5bbbe62 into rinafcode:main Aug 17, 2026
3 checks passed
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.

Reconcile entity/migration drift so the schema drift check passes strictly

2 participants