Skip to content

Commit

Permalink
AO3-6893 Patch departure the right way to prevent lock issues (otwcod…
Browse files Browse the repository at this point in the history
…e#5069)

* AO3-6893 Patch departure the right way to prevent lock issues

* Suppress false positive cop

It refers to a migration; this is not one, and we need to subclass ActiveRecord::Base
this way to ensure OriginalAdapterConnection subclasses the right thing.
  • Loading branch information
brianjaustin authored Feb 16, 2025
1 parent a6a9ff1 commit fa7bdc4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions config/initializers/monkeypatches/departure.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Fix for https://github.com/departurerb/departure/issues/110, where advisory locks are not released after migration
# is completed. This should be removed when a fix is available upstream.
module Departure
module Migration
# Make all connections in the connection pool NOT use PerconaAdapter instead of the current adapter.
# Ref https://github.com/departurerb/departure/issues/110.
def reconnect_with_percona
ActiveRecord::Base.establish_connection(connection_config.merge(adapter: "percona"))
class ConnectionBase < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
def self.establish_connection(config = nil)
super
end
end

class OriginalAdapterConnection < ConnectionBase; end
end

puts "WARNING: The monkeypatch #{__FILE__} was written for version 6.7.0 of the departure gem, but you are running #{Departure::VERSION}. Please update or remove the monkeypatch." unless Departure::VERSION == "6.7.0"

0 comments on commit fa7bdc4

Please sign in to comment.