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.
ActiveRecord::NoDatabaseError: database "app_test2" does not exist
# you ran: bundle exec parallel_rspec spec
# but never ran: bundle exec rake parallel:create parallel:prepareCommon 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.
RAILS_ENV=test bundle exec rake parallel:create
RAILS_ENV=test bundle exec rake parallel:prepare
bundle exec parallel_rspec specMatch worker count to the prepared databases
- Set the same process count for setup and run (parallel_tests -n N).
- Ensure the database config templates the worker number (TEST_ENV_NUMBER).
- 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.