16470: Avoids crashing when running the rake task db:create.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 31 Jul 2020 19:43:40 +0000 (16:43 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 7 Aug 2020 14:54:35 +0000 (11:54 -0300)
There was a behaviour change on rake tasks that avoided the creation of the
test database. All initializers are now called from rake tasks, so those
initializers with code accessing the database will fail when the database
isn't created.

See: https://github.com/rails/rails/issues/32870

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/config/initializers/legacy_jobs_api.rb

index 8f3b3cb5f8e951df55979a1f74adce8b847de652..2abe40566ecf03cc0d48054b74690c6d1d7048b6 100644 (file)
@@ -8,8 +8,13 @@
 
 require 'enable_jobs_api'
 
-Server::Application.configure do
-  if ActiveRecord::Base.connection.tables.include?('jobs')
-    check_enable_legacy_jobs_api
+Rails.application.configure do
+  begin
+    if ActiveRecord::Base.connection.tables.include?('jobs')
+      check_enable_legacy_jobs_api
+    end
+  rescue ActiveRecord::NoDatabaseError
+    # Since rails 5.2, all initializers are run by rake tasks (like db:create),
+    # see: https://github.com/rails/rails/issues/32870
   end
 end