database 'test_db' does not exist" in CI after a migration change: how to fix the setup step
Fixes the CI failure 'database test_db does not exist' that appears after a migration change, by repairing the pipeline's database setup step. Shows how to confirm the database is created before migrations run, align the setup with any renamed database, and verify the connection settings. Use when CI migrations fail on a missing database that exists in other environments. Not for migration SQL errors, connection refused errors, or local database problems.
TL;DR
The migration change is a red herring for the real bug: the CI setup step is not creating test_db before the migrate step runs, or the change renamed the database the setup creates. Read the pipeline definition, make the setup step create the exact database the migrations expect, verify the connection settings name the same database, and the pipeline goes green.
"database 'test_db' does not exist" in CI after a migration change: how to fix the setup stepSteps
- Open the CI pipeline definition and read the database setup step in order: service start, database creation, then migration. Expected: you can list the exact sequence of steps.
- Check whether any step actually creates
test_db(a createdb call, a db:create task, or a service config that provisions it). Expected: you find the gap, usually that creation was removed, renamed, or never existed for this job. - Read the migration change itself: does it reference a different database name, a new schema, or a connection setting that changed what the migrate step connects to? Expected: you know whether the change renamed the target or the setup just never created it.
- Fix the setup step so it creates
test_dbbefore migrations run, using the same name the migrations and the app config expect. Expected: the pipeline definition shows create-then-migrate in that order with matching names. - Verify the connection settings used by the migrate step name
test_db(check the env var or config the CI job passes, without printing any secrets). Then rerun the pipeline. Expected: the database exists, migrations apply, tests run.
Use this when
- CI fails with "database 'test_db' does not exist" after a migration change
- The database exists in dev or staging but not in the CI job
- The migrate step runs before anything creates the database
Not for this skill when
- The error is "connection refused" (the database server is not running at all)
- A migration's SQL itself is invalid (that fails after the database exists)
- The problem is on your local machine, not in CI
Variant phrasings
- CI migration fails database does not exist
- test database not created in CI pipeline
- database does not exist after migration change CI
Why it happens
CI databases are ephemeral: the job starts from nothing, so the pipeline must create the database every run. A migration change often touches the same files or configs as the setup step, and a rename or a reordered step silently drops the creation. Locally the database persists between runs, which is why nobody notices until CI.
Edge cases
- If the CI service provisions the database asynchronously, the create step may need a readiness wait before migrate runs.
- Multiple jobs sharing one database server need distinct database names per job, or they will collide and drop each other's databases.
- Template databases: if setup clones from a template, the template must exist too, or creation fails with a different error one step earlier.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_DppjcTmmjgwBgr02SxUqoQ