mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:21:12 +08:00
Revert "We have had errors reported due to migrations breaking and are reverting"
This reverts commit 8b46f14744d4bab9339d075825914d86da6bd5eb. It corrects the reason for the revert: We rely on SafeMigrate existing cause we call it from migrations, Zeitwerk will autoload it. Instead of previous pattern we explicitly bypass all the hacks in production mode. We need to disable SafeMigrate cause it is not thread safe. A thread safe implementation is possible but not worth the effort, we catch the issues in dev and test.
This commit is contained in:
@ -73,6 +73,7 @@ class Migration::SafeMigrate
|
||||
|
||||
def self.enable!
|
||||
return if PG::Connection.method_defined?(:exec_migrator_unpatched)
|
||||
return if ENV['RAILS_ENV'] == "production"
|
||||
|
||||
PG::Connection.class_eval do
|
||||
alias_method :exec_migrator_unpatched, :exec
|
||||
@ -92,6 +93,8 @@ class Migration::SafeMigrate
|
||||
|
||||
def self.disable!
|
||||
return if !PG::Connection.method_defined?(:exec_migrator_unpatched)
|
||||
return if ENV['RAILS_ENV'] == "production"
|
||||
|
||||
PG::Connection.class_eval do
|
||||
alias_method :exec, :exec_migrator_unpatched
|
||||
alias_method :async_exec, :async_exec_migrator_unpatched
|
||||
@ -102,6 +105,8 @@ class Migration::SafeMigrate
|
||||
end
|
||||
|
||||
def self.patch_active_record!
|
||||
return if ENV['RAILS_ENV'] == "production"
|
||||
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
ActiveRecord::Migration.prepend(SafeMigration)
|
||||
end
|
||||
|
Reference in New Issue
Block a user