module Arrival

# We need the OS not to buffer the IO to see pt-osc's output while migrating $stdout.sync = true

require 'activerecord/railtie'

Constants

VERSION

Attributes

configuration[RW]

Public Class Methods

configure() { |configuration| ... } click to toggle source
# File lib/arrival.rb, line 33
def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end
load() click to toggle source

Hooks Arrival into Rails migrations by replacing the configured database adapter

# File lib/arrival.rb, line 40
def self.load
  ActiveRecord::Migration.class_eval do
    alias_method :original_migrate, :migrate

    # Replaces the current connection adapter with the PerconaAdapter and
    # patches LHM, then it continues with the regular migration process.
    #
    # @param direction [Symbol] :up or :down
    def migrate(direction)
      reconnect_with_arrival
      # include_foreigner if defined?(Foreigner)

      # ::Lhm.migration = self
      original_migrate(direction)
    end

    # Includes the Foreigner's Mysql2Adapter implemention in
    # ArrivalAdapter to support foreign keys
    # def include_foreigner
    #   Foreigner::Adapter.safe_include(
    #     :ArrivalAdapter,
    #     Foreigner::ConnectionAdapters::Mysql2Adapter
    #   )
    # end

    # Make all connections in the connection pool to use PerconaAdapter
    # instead of the current adapter.
    def reconnect_with_arrival
      ActiveRecord::Base.establish_connection(
        TestDatabase.new.env_config.merge("adapter" => "arrival")
      )
    end
  end
end

Public Instance Methods

migrate(direction) click to toggle source

Replaces the current connection adapter with the PerconaAdapter and patches LHM, then it continues with the regular migration process.

@param direction [Symbol] :up or :down

# File lib/arrival.rb, line 48
def migrate(direction)
  reconnect_with_arrival
  # include_foreigner if defined?(Foreigner)

  # ::Lhm.migration = self
  original_migrate(direction)
end
reconnect_with_arrival() click to toggle source

Make all connections in the connection pool to use PerconaAdapter instead of the current adapter.

# File lib/arrival.rb, line 67
def reconnect_with_arrival
  ActiveRecord::Base.establish_connection(
    TestDatabase.new.env_config.merge("adapter" => "arrival")
  )
end