Skip to content

feat: migrate with the admin app, check schema.ts for drift - #2174

Merged
spaenleh merged 2 commits into
mainfrom
305-admin-owns-schema
Nov 13, 2026
Merged

spaenleh merged 2 commits into
mainfrom
305-admin-owns-schema

Conversation

@spaenleh

Copy link
Copy Markdown
Member

Core side of graasp/graasp-web#305. Depends on graasp/graasp-web#309 (admin baseline migration).

Summary

The admin app now owns the database schema (ADR 0002 in graasp/graasp-web). Core stops running drizzle migrations: it migrates with admin, and schema.ts becomes a hand-maintained description checked against the migrated database.

 CI (build-unit, test-node)
-  mise run migrate              # drizzle-kit migrate
-  mise run migration-check      # drizzle-kit generate finds nothing
+  ./.github/actions/admin-migrate
+    checkout graasp/graasp-web @ ADMIN_REF (pinned in mise.toml)
+    setup-beam from admin's mise.toml, cache deps/_build
+    scripts/migrate.sh          # DATABASE_URL=… MIX_ENV=test mix ecto.migrate
+  mise run schema-drift-check   # build-unit only
schemaDriftCheck.ts
  drizzle-kit pull           # snapshot of the database, only tables/views declared in schema.ts
  generateDrizzleJson(schema)
  normalize                  # drop drizzle comparison quirks (default opclasses, WHERE/expression
                             # spelling, unique column order, undeclared enums/sequences, view SQL text)
  generateMigration(db, schema.ts) -> any statement = drift, exit 1

pushSchema from drizzle-kit/api would do this in one call, but in 0.31.11 it drops query parameters while introspecting.

  • schema.ts now matches the admin-migrated database:
    • added admins.name/language and admin's 4 item indexes;
    • added the apps.thumbnail default;
    • used the real names of the publication_removal_notices creator FK and the maintenance PK;
    • enum_ops on item_membership.permission;
    • created_at DESC NULLS FIRST.
  • mise run migrate works locally too. It clones admin into tmp/admin; set ADMIN_DIR=../admin to use your own checkout. jest and vitest now ignore tmp/.
  • The drizzle migrate image is no longer built, and the drizzle-kit migrate/generate/check scripts are gone. The SQL files in src/drizzle/ stay as frozen history.
  • The README "Database and Migrations" section is rewritten. It still described TypeORM.

Evidence

Run locally against a fresh database migrated by admin (graasp/graasp-web#309):

  • Drift check:

    • Before (schema.ts on main): 35 statements, including ALTER TABLE "admins" DROP COLUMN "name", DROP INDEX "idx_item_type_h5p_contentid" and ALTER TABLE "maintenance" ADD CONSTRAINT "UQ_maintenance_slug" UNIQUE("slug").
    • After: schema.ts matches the database, exit 0.
  • The check still catches drift:

    alter table admins add column foo int; create index idx_test on item (lang);
    alter table item alter column description set not null
    -> DROP INDEX "idx_test";
       ALTER TABLE "item" ALTER COLUMN "description" DROP NOT NULL;
       ALTER TABLE "admins" DROP COLUMN "foo";
       exit 1
    
  • mise run check passes: prettier, tsc, and eslint with no errors.

  • I couldn't run the e2e and vitest suites locally (no Redis). This PR's CI is their first run against an admin-migrated database.

Merge Danger

Door: two-way

Reverting restores drizzle migrations in CI and the migrate image build. No database is touched by merging.

Blast Radius: CI and deploys

  • Before merging, bump ADMIN_REF from the PR-branch commit 167dd63c3 to a commit on admin's main (or a release tag) once feat: add core schema baseline migration graasp-web#309 merges. A squash merge drops the branch commit.
  • graasp-infrastructure deploys still copy and run graasp:migrate-* images. Dev keeps running the last migrate-nightly, which does nothing. A prod "Apply Migration" for a new version would fail: no image is published for it. I'm switching those workflows to admin's Admin.Release.migrate() in a separate PR.
  • Self-hosted docker/compose.yml still ships the old drizzle migrate image, which doesn't know admin's migrations. Fixing that needs a public admin migrate image (follow-up).
  • Local core databases need git and mise for mise run migrate; mise installs Erlang and Elixir for admin.

The admin app (graasp/graasp-web) now owns the database schema (ADR 0002,
graasp/graasp-web#305). Core stops running drizzle migrations.

- `mise run migrate` runs admin's migrations, from the commit pinned as
  ADMIN_REF in mise.toml, against DB_CONNECTION.
- CI migrates its test databases with admin and replaces migration-check
  with `mise run schema-drift-check`, which compares schema.ts with the
  migrated database.
- schema.ts catches up with production: admin columns and indexes, the
  apps.thumbnail default, the real names of two constraints and an opclass.
- The drizzle migrate image is no longer built.
Comment thread src/drizzle/schemaDriftCheck.ts Fixed
@sonarqubecloud

Copy link
Copy Markdown

@spaenleh
spaenleh merged commit 17249f0 into main Nov 13, 2026
8 checks passed
@spaenleh
spaenleh deleted the 305-admin-owns-schema branch November 13, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants