Skip to content

ci: exercise migrations against MySQL and PostgreSQL - #3068

Merged
tada5hi merged 2 commits into
masterfrom
ci/test-migrations
May 20, 2026
Merged

tada5hi merged 2 commits into
masterfrom
ci/test-migrations

Conversation

@tada5hi

@tada5hi tada5hi commented May 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • New tests-migrations CI 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). Every up()/down() gets exercised, not just the latest migration.
  • Pre-flight step counts compiled migrations in 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.
  • Pin docker-compose.yml images to mysql:9 and postgres:18 to match the versions used by apps/server-core/test/setup.ts, eliminating drift between the migration job and the rest of the test suite.

Closes #3067.

What it catches

  • SQL syntax errors in either DB
  • Cross-DB type / quoting mismatches
  • down() regressions in any migration (not just the latest)
  • Idempotency: re-applying the full chain after a full revert

What it still doesn't catch

Test plan

  • CI: tests-migrations (mysql) and tests-migrations (postgres) both green
  • Verify the pre-flight sanity check fails clearly if dist/adapters/database/migrations/<db>/ is empty (e.g. break the build cache, confirm the step prints ERROR: no compiled migrations…)
  • Spot-check job logs for the expected 8 migrations were found in the source code line on first migration run, eight Migration … has been reverted successfully lines during the revert loop, and 8 migrations are new migrations must be executed on the idempotency replay

Local 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

    • Added migration testing documentation.
  • Chores

    • Enhanced database migration testing in CI for MySQL and Postgres.
    • Updated database service versions in development environment.

Review Change Stack

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
Copilot AI review requested due to automatic review settings May 20, 2026 12:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-migrations GitHub 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.yml DB images to mysql:9 and postgres: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.

Comment thread .github/workflows/main.yml Resolved
Comment thread .github/workflows/main.yml Resolved
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@tada5hi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 56 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 744907df-e4b8-4b17-be16-bc6620cc4043

📥 Commits

Reviewing files that changed from the base of the PR and between d9c8f2f and cb89ead.

📒 Files selected for processing (1)
  • .github/workflows/main.yml
📝 Walkthrough

Walkthrough

This PR implements end-to-end migration testing in CI for MySQL and Postgres databases. It adds a new tests-migrations GitHub Actions job that verifies migrations run forward, revert cleanly, and re-apply idempotently. Database service container versions are pinned to MySQL 9 and Postgres 18, and the workflow is documented for local reproduction.

Changes

Database Migration Testing in CI

Layer / File(s) Summary
Database service version updates
docker-compose.yml
MySQL image updated to mysql:9 and Postgres image updated to postgres:18 to provide versioned containers for migration testing.
Migration test CI workflow
.github/workflows/main.yml
New tests-migrations job runs after build with a MySQL/Postgres matrix, verifies compiled migration files exist, starts the database service, executes migrations forward, reverts migrations by the detected count, and re-applies migrations to verify idempotency.
Migration testing documentation
.agents/testing.md
New "Migration Tests" section documents the CI workflow (forward → revert → re-run), what migration bugs it detects (SQL syntax errors, type mismatches, broken down() implementations), what it does not catch (data correctness on existing rows), and provides a local CLI example showing environment variable setup and automatic database creation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A rabbit tests migrations with care,
MySQL and Postgres everywhere,
Forward, revert, and back once more,
Every schema checked at the door! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a CI job that exercises migrations against MySQL and PostgreSQL databases, directly matching the PR's primary objective.
Linked Issues check ✅ Passed All coding requirements from issue #3067 are met: migrations are exercised against MySQL and PostgreSQL [#3067], revert is tested [#3067], idempotency is verified [#3067], and the pre-flight guard prevents silent no-ops [#3067].
Out of Scope Changes check ✅ Passed All changes are directly scoped to the migration testing requirement: the CI workflow addition, documentation of the testing process, and version pinning to match test environment dependencies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/test-migrations

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@tada5hi
tada5hi merged commit 651d41e into master May 20, 2026
10 checks passed
@tada5hi
tada5hi deleted the ci/test-migrations branch May 20, 2026 13:12
tada5hi added a commit to PrivateAIM/hub that referenced this pull request May 21, 2026
* 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.
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.

CI: migrations are not exercised against MySQL or PostgreSQL

2 participants