20978: Merge branch 'main' into 20978-instance-types
[arvados.git] / services / api / config / initializers / legacy_jobs_api.rb
index eecf337daaff7ff75e604f85f3abda828fcc0167..b6a2895f78ccb2a2f0c09897a4a786bf326babbf 100644 (file)
@@ -5,40 +5,16 @@
 # Config must be done before we  files; otherwise they
 # won't be able to use Rails.configuration.* to initialize their
 # classes.
-require_relative 'load_config.rb'
 
-Server::Application.configure do
-  # Use exec_query because the Job model isn't loaded yet
-  # it returns the string '0', not converted to integer.
-  if Rails.configuration.enable_legacy_jobs_api == false ||
-     (Rails.configuration.enable_legacy_jobs_api == "auto" &&
-      ActiveRecord::Base.connection.exec_query('select count(*) from jobs').first['count'] == '0')
-    Rails.configuration.disable_api_methods = ["jobs.create",
-                                               "pipeline_instances.create",
-                                               "pipeline_templates.create",
-                                               "jobs.get",
-                                               "pipeline_instances.get",
-                                               "pipeline_templates.get",
-                                               "jobs.list",
-                                               "pipeline_instances.list",
-                                               "pipeline_templates.list",
-                                               "jobs.index",
-                                               "pipeline_instances.index",
-                                               "pipeline_templates.index",
-                                               "jobs.update",
-                                               "pipeline_instances.update",
-                                               "pipeline_templates.update",
-                                               "jobs.queue",
-                                               "jobs.queue_size",
-                                               "job_tasks.create",
-                                               "job_tasks.get",
-                                               "job_tasks.list",
-                                               "job_tasks.index",
-                                               "job_tasks.update",
-                                               "jobs.show",
-                                               "pipeline_instances.show",
-                                               "pipeline_templates.show",
-                                               "jobs.show",
-                                               "job_tasks.show"]
+require 'enable_jobs_api'
+
+Rails.application.configure do
+  begin
+    if ENV["ARVADOS_CONFIG"] != "none" && 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