-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update rake task to accomodate rails 5.1 to 5.2 change of db:load_con…
…fig sending new prereqs CI test workflows and local dev setup requires db:create rake task. However in Rails 5.2, there was an introduction of new behavior of db:load_config (a task within db:create) which causes db:create to fail. (This is a known issue from Rails and behavior introduced after 5.1.7). To fix, we delete the new environment prerequisite of db:load_config, (db:load_config depending on environment means the app would load with all observers, sphinx indices, concerns etc which trigger a db connection, BUT can't be established because the DB does not exist yet.). However, just removing the prerequisite, will get db:create to work, but loading schema will stop working because db:load_config needs that prereq and tehrefore we bring it back after db:create, knowing we have a db to connect to.
- Loading branch information
1 parent
e8b3516
commit b44f92b
Showing
3 changed files
with
41 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
require File.expand_path('../config/application', __FILE__) | ||
|
||
Rails.application.load_tasks | ||
|
||
# In Rails 5.2 the `load_config` task was made dependent on `environment` | ||
# to enable credentials reading, see https://github.com/rails/rails/pull/31135 | ||
# This causes the whole app to initialize before `db:create` and that | ||
# causes a database connection for observers, sphinx, concerns, etc, that cant be established | ||
# when DB does not exist yet. | ||
# See SO: https://stackoverflow.com/questions/72147515/rails-5-2-load-order-breaks-dbcreate | ||
# While clearing the environment prerequisite of load_config will help db:create | ||
# and create the db, other tasks like db:schema:load and our panoptes talk rake tasks | ||
# will actually need the prereq, and therefore we bring back the environment prereq | ||
# for other rake tasks. We do this to keep our CI test workflows and local dev environment setup functional. | ||
|
||
Rake::Task['db:load_config'].prerequisites.delete("environment") | ||
Rake::Task.tasks.select { |task| | ||
next if task.name == "db:create" | ||
task.name.start_with?("db:") && task.prerequisites.include?("load_config") | ||
}.each { |task| | ||
task.prerequisites.insert(task.prerequisites.index("load_config"), "environment") | ||
} | ||
Rake::Task.tasks.select { |task| | ||
task.prerequisites.include?("db:load_config") | ||
}.each { |task| | ||
task.prerequisites.insert(task.prerequisites.index("db:load_config"), "environment") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Subject < ApplicationRecord | ||
self.primary_key = :id | ||
include Focusable | ||
belongs_to :project | ||
end |