Module: SchemaFerry::Source::ConnectionRegistry

Defined in:
lib/schema_ferry/source/connection_registry.rb

Class Method Summary collapse

Class Method Details

.with_connection(url) ⇒ Object

Uses a fresh ConnectionHandler per call so the pool is fully isolated from ActiveRecord::Base and any host Rails app connections. AR 7.2+ banned anonymous AR subclasses, so we bypass that path entirely.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/schema_ferry/source/connection_registry.rb', line 9

def self.with_connection(url)
  handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
  begin
    pool = handler.establish_connection(url, owner_name: "schema_ferry")
    conn = pool.checkout
    conn.verify!
  rescue ActiveRecord::ActiveRecordError => e
    raise ConnectionError, e.message
  end

  begin
    yield conn
  ensure
    pool.checkin(conn)
  end
ensure
  handler&.clear_all_connections!
end