diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-02-27 07:21:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-27 07:21:47 -0500 |
commit | 4464a391a0704d7434e751aa38f0c684349c42d9 (patch) | |
tree | b24e7ea853ed82295df444de9419d152cc94fd53 /activerecord/lib | |
parent | 5bf55685a3317f2716687a8fe471021a1bc042f0 (diff) | |
parent | 0bd7f4ad44c53832ec029a53a88461e9f6eab6f1 (diff) | |
download | rails-4464a391a0704d7434e751aa38f0c684349c42d9.tar.gz rails-4464a391a0704d7434e751aa38f0c684349c42d9.tar.bz2 rails-4464a391a0704d7434e751aa38f0c684349c42d9.zip |
Merge pull request #31189 from tgxworld/raise_error_when_advisory_lock_is_not_releases
Raise an error if advisory lock in migrator was not released.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 5322571820..663b3c590a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -140,6 +140,7 @@ module ActiveRecord class ConcurrentMigrationError < MigrationError #:nodoc: DEFAULT_MESSAGE = "Cannot run migrations because another migration process is currently running.".freeze + RELEASE_LOCK_FAILED_MESSAGE = "Failed to release advisory lock".freeze def initialize(message = DEFAULT_MESSAGE) super @@ -1355,12 +1356,17 @@ module ActiveRecord def with_advisory_lock lock_id = generate_migrator_advisory_lock_id - got_lock = Base.connection.get_advisory_lock(lock_id) + connection = Base.connection + got_lock = connection.get_advisory_lock(lock_id) raise ConcurrentMigrationError unless got_lock load_migrated # reload schema_migrations to be sure it wasn't changed by another process before we got the lock yield ensure - Base.connection.release_advisory_lock(lock_id) if got_lock + if got_lock && !connection.release_advisory_lock(lock_id) + raise ConcurrentMigrationError.new( + ConcurrentMigrationError::RELEASE_LOCK_FAILED_MESSAGE + ) + end end MIGRATOR_SALT = 2053462845 |