Class: Sequel::SimpleMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/extensions/migration.rb

Overview

Migration class used by the Sequel.migration DSL, using instances for each migration, unlike the Migration class, which uses subclasses for each migration. Part of the migration extension.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimpleMigration

Don’t set transaction use by default.



101
102
103
# File 'lib/sequel/extensions/migration.rb', line 101

def initialize
  @use_transactions = nil
end

Instance Attribute Details

#downObject

Proc used for the down action



91
92
93
# File 'lib/sequel/extensions/migration.rb', line 91

def down
  @down
end

#upObject

Proc used for the up action



94
95
96
# File 'lib/sequel/extensions/migration.rb', line 94

def up
  @up
end

#use_transactionsObject

Whether to use transactions for this migration, default depends on the database.



98
99
100
# File 'lib/sequel/extensions/migration.rb', line 98

def use_transactions
  @use_transactions
end

Instance Method Details

#apply(db, direction) ⇒ Object

Apply the appropriate block on the Database instance using instance_exec.

Raises:

  • (ArgumentError)


107
108
109
110
111
112
# File 'lib/sequel/extensions/migration.rb', line 107

def apply(db, direction)
  raise(ArgumentError, "Invalid migration direction specified (#{direction.inspect})") unless [:up, :down].include?(direction)
  if prok = public_send(direction)
    db.instance_exec(&prok)
  end
end