mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Re-exec rake after creating database (#31120)
By design, db:create initializes the Rails app with SKIP_DB=true. That means that SiteSettings get set up with the LocalProcessProvider instead of the DBProvider. In other words: any calls to site settings will return the default, rather then the actual value in the database. Running db:migrate in the same rake invocation means that rails will not be re-initialized, and so skip_db will remain true. Site settings accessed during migrations and fixtures will therefore return incorrect values. One example of this is that running bin/rake db:create db:migrate repeatedly in a development environment will cause the FAQ topic to be seeded repeatedly, because the seed logic does not have access to the site setting which stores the already-seeded topic id. This commit will automatically re-exec the Rake command if any tasks are specified after `db:create`
This commit is contained in:
parent
8d810f9271
commit
c8718a64dd
@ -54,7 +54,14 @@ end
|
||||
begin
|
||||
reqs = Rake::Task["db:create"].prerequisites.map(&:to_sym)
|
||||
Rake::Task["db:create"].clear_prerequisites
|
||||
Rake::Task["db:create"].enhance(["db:force_skip_persist"] + reqs)
|
||||
Rake::Task["db:create"].enhance(["db:force_skip_persist"] + reqs) do
|
||||
# after creating the db, we need to fully reboot the Rails app to make sure
|
||||
# things like SiteSetting work correctly for future rake tasks.
|
||||
db_create_index = ARGV.find_index("db:create")
|
||||
if db_create_index < ARGV.length - 1
|
||||
exec "#{Rails.root}/bin/rake", *ARGV[db_create_index + 1..-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task "db:drop" => [:load_config] do |_, args|
|
||||
|
Loading…
Reference in New Issue
Block a user