Class: Sequel::MigrationDSL

Inherits:
BasicObject
Defined in:
lib/sequel/extensions/migration.rb

Overview

Internal class used by the Sequel.migration DSL, part of the migration extension.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicObject

const_missing

Constructor Details

#initialize(&block) ⇒ MigrationDSL

Create a new migration class, and instance_exec the block.



125
126
127
128
129
# File 'lib/sequel/extensions/migration.rb', line 125

def initialize(&block)
  @migration = SimpleMigration.new
  Migration.descendants << migration
  instance_exec(&block)
end

Instance Attribute Details

#migrationObject (readonly)

The underlying SimpleMigration instance



118
119
120
# File 'lib/sequel/extensions/migration.rb', line 118

def migration
  @migration
end

Class Method Details

.create(&block) ⇒ Object



120
121
122
# File 'lib/sequel/extensions/migration.rb', line 120

def self.create(&block)
  new(&block).migration
end

Instance Method Details

#change(&block) ⇒ Object

Creates a reversible migration. This is the same as creating the same block with up, but it also calls the block and attempts to create a down block that will reverse the changes made by the block.

There are no guarantees that this will work perfectly in all cases, but it works for some simple cases.



158
159
160
161
# File 'lib/sequel/extensions/migration.rb', line 158

def change(&block)
  migration.up = block
  migration.down = MigrationReverser.new.reverse(&block)
end

#down(&block) ⇒ Object

Defines the migration’s down action.



132
133
134
# File 'lib/sequel/extensions/migration.rb', line 132

def down(&block)
  migration.down = block
end

#no_transactionObject

Disable the use of transactions for the related migration



137
138
139
# File 'lib/sequel/extensions/migration.rb', line 137

def no_transaction
  migration.use_transactions = false
end

#revert(&block) ⇒ Object

Creates a revert migration. This is the same as creating the same block with down, but it also calls the block and attempts to create a up block that will reverse the changes made by the block. This is designed to revert the changes in the provided block.

There are no guarantees that this will work perfectly in all cases, but it works for some simple cases.



171
172
173
174
# File 'lib/sequel/extensions/migration.rb', line 171

def revert(&block)
  migration.down = block
  migration.up = MigrationReverser.new.reverse(&block)
end

#transactionObject

Enable the use of transactions for the related migration



142
143
144
# File 'lib/sequel/extensions/migration.rb', line 142

def transaction
  migration.use_transactions = true
end

#up(&block) ⇒ Object

Defines the migration’s up action.



147
148
149
# File 'lib/sequel/extensions/migration.rb', line 147

def up(&block)
  migration.up = block
end