Module: SafePgMigrations::StrongMigrationsIntegration

Included in:
Migration
Defined in:
lib/safe-pg-migrations/plugins/strong_migrations_integration.rb

Constant Summary collapse

SAFE_METHODS =
%i[
  execute
  add_index
  add_reference
  add_belongs_to
  change_column_null
  add_foreign_key
  add_check_constraint
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initializeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/safe-pg-migrations/plugins/strong_migrations_integration.rb', line 6

def initialize
  return unless strong_migration_available?

  StrongMigrations.disable_check(:add_column_default)
  StrongMigrations.disable_check(:add_column_default_callable)
  StrongMigrations.add_check do |method, args|
    next unless method == :add_column

    options = args.last.is_a?(Hash) ? args.last : {}
    default = options[:default]
    default_value_backfill = options.fetch(:default_value_backfill, :auto)

    next unless default_value_backfill == :update_in_batches

    stop! StrongMigrationsIntegration.send(:backfill_check_message, default)
  end
end

Instance Method Details

#add_column(table_name, *args, **options) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/safe-pg-migrations/plugins/strong_migrations_integration.rb', line 82

def add_column(table_name, *args, **options)
  return super unless respond_to?(:safety_assured)

  default_value_backfill = options.fetch(:default_value_backfill, :auto)

  # Auto backfill is safe - use safety_assured
  return safety_assured { super } if default_value_backfill == :auto

  # :update_in_batches always requires explicit safety_assured (volatile defaults will be
  # blocked by the check above before reaching this point)
  super
end