Module: Arrival

Defined in:
lib/arrival.rb,
lib/arrival/errors.rb,
lib/arrival/logger.rb,
lib/arrival/option.rb,
lib/arrival/runner.rb,
lib/arrival/command.rb,
lib/arrival/railtie.rb,
lib/arrival/version.rb,
lib/arrival/user_options.rb,
lib/arrival/cli_generator.rb,
lib/arrival/configuration.rb,
lib/arrival/alter_argument.rb,
lib/arrival/connection_details.rb

Overview

require ‘activerecord/railtie’

Defined Under Namespace

Classes: AlterArgument, ArgumentsNotSupported, CliGenerator, Command, CommandNotFoundError, Configuration, ConnectionDetails, Error, InvalidAlterStatement, Logger, NoStatusError, Option, Runner, SignalError, UserOptions

Constant Summary collapse

VERSION =
'0.1.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



30
31
32
# File 'lib/arrival.rb', line 30

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



33
34
35
36
# File 'lib/arrival.rb', line 33

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.loadObject

Hooks Arrival into Rails migrations by replacing the configured database adapter



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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