From fd01a7a051fe696afe28b671e15c9dbb23224fb0 Mon Sep 17 00:00:00 2001 From: Sven Krieger <37476281+svkrieger@users.noreply.github.com> Date: Wed, 17 Apr 2024 14:30:09 +0200 Subject: [PATCH] Fix backwards compatibility github actions `bundle exec rake db:parallel:migrate` (which is also used in the backwards compatibility tests) failed since introducing new migration logging (6d2f0fa). The error was `DB_CONNECTION_STRING not set`. This is because when using parallel test execution `POSTGRES_CONNECTION_PREFIX` is used. `DB_CONNECTION_STRING` is set after `DbConfig.new` was called. So the new logging setup has been moved after this command. --- lib/tasks/db.rake | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 70a766c5e51..9326c1376a1 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -242,26 +242,32 @@ namespace :db do end def migrate - logging_output - db_logger = Steno.logger('cc.db.migrations') + # The following block, which loads the test DB config is only needed for running migrations in parallel (only in tests) + # It sets the `DB_CONNECTION_STRING` env variable from `POSTGRES|MYSQL_CONNECTION_PREFIX` + test_database number begin require_relative '../../spec/support/bootstrap/db_config' DbConfig.new rescue LoadError - # Only needed when running tests + # In production the test DB config is not available nor needed, so we ignore this error. end + + logging_output + db_logger = Steno.logger('cc.db.migrations') DBMigrator.from_config(RakeConfig.config, db_logger).apply_migrations end def rollback(number_to_rollback) - logging_output - db_logger = Steno.logger('cc.db.migrations') + # The following block, which loads the test DB config is only needed for running migrations in parallel (only in tests) + # It sets the `DB_CONNECTION_STRING` env variable from `POSTGRES|MYSQL_CONNECTION_PREFIX` + test_database number begin require_relative '../../spec/support/bootstrap/db_config' DbConfig.new rescue LoadError - # Only needed when running tests + # In production the test DB config is not available nor needed, so we ignore this error. end + + logging_output + db_logger = Steno.logger('cc.db.migrations') DBMigrator.from_config(RakeConfig.config, db_logger).rollback(number_to_rollback) end