Repository navigation
ci: exercise migrations against MySQL and PostgreSQL - #3068
Conversation
Adds a tests-migrations job that runs `migration run`, reverts every migration in reverse order, and re-applies the chain against fresh MySQL and PostgreSQL containers. Catches SQL syntax errors, cross-DB type mismatches, and down() regressions that the existing tests-server-core suite misses because it builds the schema via dataSource.synchronize() (see apps/server-core/test/app/database.ts). A pre-flight step asserts that the compiled migrations exist under dist/adapters/database/migrations/<db>/ — without this guard, an incorrect working directory makes typeorm silently report "No migrations are pending" with exit 0. Pin docker-compose images to mysql:9 and postgres:18 to match the versions used by apps/server-core/test/setup.ts, eliminating image-version drift between the migration job and the rest of the test suite. Closes #3067
There was a problem hiding this comment.
Pull request overview
Adds dedicated CI coverage to execute TypeORM migrations end-to-end against MySQL and PostgreSQL, ensuring every up() and down() path is exercised (including a full revert + re-apply idempotency replay), and aligns local Docker images with the versions used in server-core tests.
Changes:
- Add
tests-migrationsGitHub Actions job to run/revert/re-run migrations against fresh MySQL + Postgres containers. - Add a pre-flight check intended to fail loudly if compiled migrations are missing from
apps/server-core/dist/.... - Pin
docker-compose.ymlDB images tomysql:9andpostgres:18, and document the new migration test job.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
docker-compose.yml |
Pins MySQL/Postgres image tags to match versions used by server-core testcontainers. |
.github/workflows/main.yml |
Introduces tests-migrations CI job to run migrations forward, revert all, and re-apply for idempotency. |
.agents/testing.md |
Documents the new migration CI job and its coverage/limitations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR implements end-to-end migration testing in CI for MySQL and Postgres databases. It adds a new ChangesDatabase Migration Testing in CI
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Two issues caught in review: 1. The pre-flight `count=$(ls ... | wc -l | ...)` runs under the GitHub Actions default `bash -eo pipefail`. When the glob matches zero files, ls exits non-zero and pipefail aborts the command substitution before the custom "no compiled migrations" message can print. Replaced with a bash array + `shopt -s nullglob`, which handles both missing-directory and no-matches identically (count=0) without invoking a pipeline. 2. `mysqladmin ping` without credentials returns exit 0 even when MySQL replies "Access denied" — so the wait loop terminated as soon as the TCP port opened, before the auth subsystem was ready, racing the migration step. Pass MYSQL_PWD via `docker compose exec -e` and `-uroot` to force a real authenticated ping; exit code is now non-zero until the server accepts our credentials.
* ci: exercise migrations against MySQL and PostgreSQL
The existing `test` job builds the schema via `dataSource.synchronize()` in
`apps/<service>/test/app/database.ts`, so migration files in
`apps/<service>/src/adapters/database/migrations/{mysql,postgres}/` are never
exercised. SQL syntax errors and broken `down()` regressions only surface in
production deployments.
Add a `tests-migrations` job that runs the migration CLI end-to-end for
server-core, server-storage, and server-telemetry against fresh MySQL 9 and
Postgres 18 containers: `run` -> revert all in reverse order -> `run`
(idempotency replay). Every `up()` / `down()` is exercised, not just the latest.
A pre-flight step counts compiled migrations and fails loudly if zero — without
this guard, typeorm silently reports "No migrations are pending" with exit 0
when the CLI runs from the wrong working directory, which is the same silent-
pass failure mode this job exists to fix.
Pin `docker-compose.yml` images to `mysql:9` and `postgres:18` to match the
versions the existing test job uses, so local migration runs match CI.
Refs authup/authup#3067, authup/authup#3068.
* ci(migrations): auth mysqladmin probe; document full local flow
- mysqladmin ping now passes -uroot -pstart123 to avoid Access denied on
MySQL 8+ images (matches the existing test job).
- Expand the local repro in .agents/testing.md to show the full
run -> revert xN -> run cycle and a Postgres env variant.
* build: regenerate package-lock.json
The release commit 14e5cca bumped apps/client-ui/package.json (and others)
to use ^0.9.0 of @privateaim/kit / @privateaim/server-kit, but the
package-lock.json node for apps/client-ui still recorded the previous ^0.8.31
constraints. As a result npm ci could not satisfy the lockfile and failed
with 'Missing: @privateaim/[email protected] from lock file', breaking CI on master
and every branch since the release.
Regenerating the lockfile records the workspace 0.9.0 versions plus the
0.8.43 registry copies that server-storage-kit (^0.8.21) and server-test-kit
(^0.8.37) still pull in — no package.json changes.
* fix(build): bump stale kit/server-kit refs to ^0.9.0
server-storage-kit and server-test-kit referenced @privateaim/kit /
@privateaim/server-kit at ^0.8.21 / ^0.8.37, but the workspace versions
are now 0.9.0. npm therefore pulled the registry copies of those packages
into nested node_modules — and the published 0.8.43 tarballs do not
contain the dist/ directory, so any consumer of server-storage-kit or
server-test-kit failed at import time with:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module
'.../server-storage-kit/node_modules/@privateaim/server-kit/dist/index.mjs'
Bumping the constraints to ^0.9.0 makes npm use the local workspace
package (which has dist/), eliminating the nested broken installs.
Drops 102 lines of stale registry entries from package-lock.json that
were added by the previous regenerate.
* ci(migrations): pipefail-safe count and unauthed-warning-free mysqladmin
Mirrors authup/authup@cb89ead85:
- Migration count step now uses 'shopt -s nullglob' + bash array glob
instead of 'ls | wc -l'. Under set -e -o pipefail (GHA default) the
pipe form can fail when the directory does not exist — which is
precisely the case this step is designed to detect.
- mysqladmin readiness probe now passes the password via the MYSQL_PWD
environment variable rather than -p on the command line, eliminating
the 'Using a password on the command line interface can be insecure'
warning.
* ci(migrations): use GHA services: blocks instead of docker compose
Aligns the migration job with the existing test job in this workflow,
which already uses GHA services: for mysql:9 / postgres:18. Removes the
separate 'Start mysql/postgres' and 'Wait for ... ready' steps — GHA
manages container lifecycle and health-check polling.
The docker-compose.yml still exists for local development; only the CI
job switches off it. docs say to run 'docker compose up' locally; that
remains accurate.
Summary
tests-migrationsCI job runs the migration CLI end-to-end against fresh MySQL and PostgreSQL containers:migration run→ revert all in reverse order →migration run(idempotency replay). Everyup()/down()gets exercised, not just the latest migration.dist/adapters/database/migrations/<db>/and fails loudly if zero. Without this guard, typeorm silently reports "No migrations are pending" with exit 0 when the CLI runs from the wrong working directory — the same failure mode this issue exists to fix.docker-compose.ymlimages tomysql:9andpostgres:18to match the versions used byapps/server-core/test/setup.ts, eliminating drift between the migration job and the rest of the test suite.Closes #3067.
What it catches
down()regressions in any migration (not just the latest)What it still doesn't catch
UPDATE/INSERTmigrations against pre-existing rows (the migrations run against an empty DB). This is the scenario that caused the MySQLBINARYbug in refactor!: drop user.client_id, backfill canonical identifier columns #3066 and is listed as a stretch goal in CI: migrations are not exercised against MySQL or PostgreSQL #3067 — not addressed here.Test plan
tests-migrations (mysql)andtests-migrations (postgres)both greendist/adapters/database/migrations/<db>/is empty (e.g. break the build cache, confirm the step printsERROR: no compiled migrations…)8 migrations were found in the source codeline on firstmigration run, eightMigration … has been reverted successfullylines during the revert loop, and8 migrations are new migrations must be executedon the idempotency replayLocal verification (already done): full run → revert-all → re-apply cycle against the docker-compose MySQL and PostgreSQL containers — all eight migrations applied, all eight reverted in reverse order, all eight re-applied.
Summary by CodeRabbit
Documentation
Chores