Module: Departure

Defined in:
lib/departure.rb,
lib/departure/dsn.rb,
lib/departure/errors.rb,
lib/departure/logger.rb,
lib/departure/option.rb,
lib/departure/runner.rb,
lib/departure/command.rb,
lib/departure/railtie.rb,
lib/departure/version.rb,
lib/departure/null_logger.rb,
lib/departure/user_options.rb,
lib/departure/cli_generator.rb,
lib/departure/configuration.rb,
lib/departure/alter_argument.rb,
lib/departure/logger_factory.rb,
lib/departure/connection_base.rb,
lib/departure/connection_details.rb,
lib/departure/log_sanitizers/password_sanitizer.rb

Defined Under Namespace

Modules: LogSanitizers, LoggerFactory Classes: AlterArgument, ArgumentsNotSupported, CliGenerator, Command, CommandNotFoundError, Configuration, ConnectionBase, ConnectionDetails, DSN, Error, InvalidAlterStatement, Logger, NoStatusError, NullLogger, Option, Railtie, Runner, SignalError, UserOptions

Constant Summary collapse

VERSION =
'6.2.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



25
26
27
# File 'lib/departure.rb', line 25

def configuration
  @configuration
end

Class Method Details

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

Yields:



28
29
30
31
# File 'lib/departure.rb', line 28

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

.loadObject

Hooks Percona Migrator into Rails migrations by replacing the configured database adapter



35
36
37
38
39
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
# File 'lib/departure.rb', line 35

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_percona
      include_foreigner if defined?(Foreigner)

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

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

    # Make all connections in the connection pool to use PerconaAdapter
    # instead of the current adapter.
    def reconnect_with_percona
      connection_config = ActiveRecord::Base
        .connection_config.merge(adapter: 'percona')
      Departure::ConnectionBase.establish_connection(connection_config)
    end
  end
end