Skip to content
Latchkey

Ruby parallel_tests "database does not exist" in CI

parallel_tests runs N test processes, each needing its own numbered database (app_test, app_test2, ...). The job failed because those per-process databases were never created or migrated before the run started.

What this error means

Running parallel_tests fails in some or all workers with "database app_test2 does not exist" (or pending migrations). The single-process suite passes; only the parallel databases are missing.

CI log
ActiveRecord::NoDatabaseError: database "app_test2" does not exist

# you ran: bundle exec parallel_rspec spec
# but never ran: bundle exec rake parallel:create parallel:prepare

Common causes

Per-process databases not created

parallel_tests expects a database per worker. Without rake parallel:create the extra numbered databases (app_test2, app_test3) do not exist, so those workers fail.

Schema not loaded into the parallel databases

Even if created, the databases need the schema/migrations. Skipping parallel:prepare leaves them empty, so queries fail on missing tables.

How to fix it

Create and prepare the parallel databases

Run the parallel setup tasks before the parallel test command.

Terminal
RAILS_ENV=test bundle exec rake parallel:create
RAILS_ENV=test bundle exec rake parallel:prepare
bundle exec parallel_rspec spec

Match worker count to the prepared databases

  1. Set the same process count for setup and run (parallel_tests -n N).
  2. Ensure the database config templates the worker number (TEST_ENV_NUMBER).
  3. Cache nothing stateful about the DBs between runs - recreate them each job.

How to prevent it

  • Run parallel:create and parallel:prepare before parallel_tests in CI.
  • Keep the worker count consistent between setup and execution.
  • Template the database name on TEST_ENV_NUMBER in database config.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →