Module: SafePgMigrations
- Defined in:
- lib/safe-pg-migrations/base.rb,
lib/safe-pg-migrations/railtie.rb,
lib/safe-pg-migrations/version.rb,
lib/safe-pg-migrations/configuration.rb,
lib/safe-pg-migrations/helpers/logger.rb,
lib/safe-pg-migrations/helpers/pg_helper.rb,
lib/safe-pg-migrations/helpers/batch_over.rb,
lib/safe-pg-migrations/helpers/index_helper.rb,
lib/safe-pg-migrations/helpers/satisfied_helper.rb,
lib/safe-pg-migrations/helpers/volatile_default.rb,
lib/safe-pg-migrations/helpers/statements_helper.rb,
lib/safe-pg-migrations/plugins/statement_insurer.rb,
lib/safe-pg-migrations/plugins/statement_retrier.rb,
lib/safe-pg-migrations/plugins/verbose_sql_logger.rb,
lib/safe-pg-migrations/plugins/idempotent_statements.rb,
lib/safe-pg-migrations/plugins/blocking_activity_logger.rb,
lib/safe-pg-migrations/plugins/useless_statements_logger.rb,
lib/safe-pg-migrations/helpers/blocking_activity_selector.rb,
lib/safe-pg-migrations/helpers/session_setting_management.rb,
lib/safe-pg-migrations/helpers/blocking_activity_formatter.rb,
lib/safe-pg-migrations/polyfills/index_definition_polyfill.rb,
lib/safe-pg-migrations/plugins/statement_insurer/add_column.rb,
lib/safe-pg-migrations/plugins/strong_migrations_integration.rb,
lib/safe-pg-migrations/polyfills/verbose_query_logs_polyfill.rb,
lib/safe-pg-migrations/plugins/statement_insurer/change_column_null.rb,
lib/safe-pg-migrations/plugins/statement_insurer/remove_column_index.rb
Defined Under Namespace
Modules: BlockingActivityLogger, Helpers, IdempotentStatements, Migration, Polyfills, StatementInsurer, StatementRetrier, StrongMigrationsIntegration, UselessStatementsLogger
Classes: Configuration, Railtie, VerboseSqlLogger
Constant Summary
collapse
- PLUGINS =
Order matters: the bottom-most plugin will have precedence
[
BlockingActivityLogger,
IdempotentStatements,
StatementRetrier,
StatementInsurer,
UselessStatementsLogger,
Polyfills::IndexDefinitionPolyfill,
].freeze
- VERSION =
'4.0.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.current_migration ⇒ Object
Returns the value of attribute current_migration.
36
37
38
|
# File 'lib/safe-pg-migrations/base.rb', line 36
def current_migration
@current_migration
end
|
.pg_version_num ⇒ Object
Returns the value of attribute pg_version_num.
36
37
38
|
# File 'lib/safe-pg-migrations/base.rb', line 36
def pg_version_num
@pg_version_num
end
|
Class Method Details
.alternate_connection ⇒ Object
66
67
68
|
# File 'lib/safe-pg-migrations/base.rb', line 66
def alternate_connection
@alternate_connection ||= ActiveRecord::Base.connection_pool.send(:new_connection)
end
|
.close_alternate_connection ⇒ Object
70
71
72
73
74
75
|
# File 'lib/safe-pg-migrations/base.rb', line 70
def close_alternate_connection
return unless @alternate_connection
@alternate_connection.disconnect!
@alternate_connection = nil
end
|
.config ⇒ Object
87
88
89
|
# File 'lib/safe-pg-migrations/base.rb', line 87
def config
@config ||= Configuration.new
end
|
.get_pg_version_num(connection) ⇒ Object
91
92
93
|
# File 'lib/safe-pg-migrations/base.rb', line 91
def get_pg_version_num(connection)
connection.query_value('SHOW server_version_num').to_i
end
|
.setup_and_teardown(migration, connection, &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/safe-pg-migrations/base.rb', line 38
def setup_and_teardown(migration, connection, &block)
@pg_version_num = get_pg_version_num(connection)
@alternate_connection = nil
with_current_migration(migration) do
stdout_sql_logger = VerboseSqlLogger.new.setup if verbose?
VerboseSqlLogger.new.setup if verbose?
PLUGINS.each { |plugin| connection.extend(plugin) }
connection.with_setting :lock_timeout, SafePgMigrations.config.pg_lock_timeout do
connection.with_setting :statement_timeout, SafePgMigrations.config.pg_statement_timeout, &block
end
ensure
stdout_sql_logger&.teardown
end
ensure
close_alternate_connection
end
|
.verbose? ⇒ Boolean
77
78
79
80
81
82
83
84
85
|
# File 'lib/safe-pg-migrations/base.rb', line 77
def verbose?
unless current_migration.class._safe_pg_migrations_verbose.nil?
return current_migration.class._safe_pg_migrations_verbose
end
return ENV['SAFE_PG_MIGRATIONS_VERBOSE'] == '1' if ENV['SAFE_PG_MIGRATIONS_VERBOSE']
return Rails.env.production? if defined?(Rails)
false
end
|
.with_current_migration(migration, &block) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/safe-pg-migrations/base.rb', line 58
def with_current_migration(migration, &block)
@current_migration = migration
yield block
ensure
@current_migration = nil
end
|