Module: OnlineMigrations::Migration

Defined in:
lib/online_migrations/migration.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/online_migrations/migration.rb', line 18

def method_missing(method, *args, &block)
  if ar_schema?
    super
  elsif command_checker.check(method, *args, &block)
    if in_transaction?
      super
    elsif method == :with_lock_retries
      connection.with_lock_retries(*args, &block)
    else
      connection.with_lock_retries { super }
    end
  end
end

Instance Method Details

#safety_assured(&block) ⇒ Object

Mark a command in the migration as safe, despite using a method that might otherwise be dangerous.

Examples:

safety_assured { remove_column(:users, :some_column) }


47
48
49
# File 'lib/online_migrations/migration.rb', line 47

def safety_assured(&block)
  command_checker.class.safety_assured(&block)
end

#stop!(message, header: "Custom check") ⇒ Object

Stop running migrations.

It is intended for use in custom checks.

Examples:

OnlineMigrations.config.add_check do |method, args|
  if method == :add_column && args[0].to_s == "users"
    stop!("No more columns on the users table")
  end
end

Raises:



62
63
64
# File 'lib/online_migrations/migration.rb', line 62

def stop!(message, header: "Custom check")
  raise OnlineMigrations::UnsafeMigration, "⚠️  [online_migrations] #{header} ⚠️\n\n#{message}\n\n"
end