module SafePgMigrations
Constants
- PLUGINS
Order matters: the bottom-most plugin will have precedence
- VERSION
Attributes
current_migration[R]
pg_version_num[R]
Public Class Methods
alternate_connection()
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 43 def alternate_connection @alternate_connection ||= ActiveRecord::Base.connection_pool.send(:new_connection) end
close_alternate_connection()
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 47 def close_alternate_connection return unless @alternate_connection @alternate_connection.disconnect! @alternate_connection = nil end
config()
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 71 def config @config ||= Configuration.new end
get_pg_version_num(connection)
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 39 def get_pg_version_num(connection) connection.query_value('SHOW server_version_num').to_i end
say(*args)
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 54 def say(*args) return unless current_migration current_migration.say(*args) end
say_method_call(method, *args)
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 60 def say_method_call(method, *args) say "#{method}(#{args.map(&:inspect) * ', '})", true end
setup_and_teardown(migration, connection) { || ... }
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 25 def setup_and_teardown(migration, connection) @pg_version_num = get_pg_version_num(connection) @alternate_connection = nil @current_migration = migration stdout_sql_logger = VerboseSqlLogger.new.setup if verbose? PLUGINS.each { |plugin| connection.extend(plugin) } connection.with_setting(:lock_timeout, SafePgMigrations.config.pg_safe_timeout) { yield } ensure close_alternate_connection @current_migration = nil stdout_sql_logger&.teardown end
verbose?()
click to toggle source
# File lib/safe-pg-migrations/base.rb, line 64 def verbose? return ENV['SAFE_PG_MIGRATIONS_VERBOSE'] == '1' if ENV['SAFE_PG_MIGRATIONS_VERBOSE'] return Rails.env.production? if defined?(Rails) false end