From 412e1ebbe287cba4d64f2fb1e3680a916f5ce971 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 31 Dec 2019 14:07:44 +1100 Subject: [PATCH] DEV: correct parallel specs rake tasks This used to work due to side effects. `rake parallel:migrate` used to work very inconsistently and would only migrate some of the databases. This introduces the recommended change to db.yml so the correct database is found based off TEST_ENV_NUMBER if for some reason we did not set it using RAILS_DB Also avoids a bunch of schema dumping which is not needed when migrating parallel specs DB number 1 is very odd cause for whatever reason parallel spec is not setting it. --- config/database.yml | 15 ++++++++++++++- lefthook.yml | 2 ++ lib/tasks/db.rake | 9 ++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config/database.yml b/config/database.yml index a9be456195a..c8f44946d92 100644 --- a/config/database.yml +++ b/config/database.yml @@ -16,10 +16,23 @@ development: # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. + +<% + test_db = ENV["RAILS_DB"] + if !test_db.present? + test_db = "discourse_test" + + if num = ENV["TEST_ENV_NUMBER"] + num = num.presence || "1" + test_db += "_#{num}" + end + end +%> + test: prepared_statements: false adapter: postgresql - database: <%= ENV["RAILS_DB"] ? ENV["RAILS_DB"] : "discourse_test" %> + database: <%= test_db %> min_messages: warning pool: 5 timeout: 5000 diff --git a/lefthook.yml b/lefthook.yml index 1ac4f9c87f0..df4a83f4e78 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -9,6 +9,8 @@ pre-commit: run: yarn eslint --ext .es6 -f compact {staged_files} yaml-syntax: glob: "*.{yaml,yml}" + # database.yml is an erb file not a yaml file + exclude: "database.yml" run: bundle exec yaml-lint {staged_files} commands: &commands diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 05cf2bd3433..626acd57602 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -68,20 +68,23 @@ end # we need to run seed_fu every time we run rake db:migrate task 'db:migrate' => ['load_config', 'environment', 'set_locale'] do |_, args| + ActiveRecord::Tasks::DatabaseTasks.migrate - Rake::Task['db:_dump'].invoke + if !Discourse.is_parallel_test? + Rake::Task['db:_dump'].invoke + end SeedFu.seed(DiscoursePluginRegistry.seed_paths) - unless Discourse.skip_post_deployment_migrations? + if !Discourse.skip_post_deployment_migrations? puts print "Optimizing site icons... " SiteIconManager.ensure_optimized! puts "Done" end - if MultisiteTestHelpers.load_multisite? + if !Discourse.is_parallel_test? && MultisiteTestHelpers.load_multisite? system("RAILS_DB=discourse_test_multisite rake db:migrate") end end