class Sequel::MigrationReverser

Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.

Public Class Methods

new() click to toggle source
    # File lib/sequel/extensions/migration.rb
165 def initialize
166   @actions = []
167 end

Public Instance Methods

reverse(&block) click to toggle source

Reverse the actions for the given block. Takes the block given and returns a new block that reverses the actions taken by the given block.

    # File lib/sequel/extensions/migration.rb
172 def reverse(&block)
173   begin
174     instance_exec(&block)
175   rescue
176     just_raise = true
177   end
178   if just_raise
179     Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'}
180   else
181     actions = @actions.reverse
182     Proc.new do
183       actions.each do |a|
184         pr = a.last.is_a?(Proc) ? a.pop : nil
185         # Allow calling private methods as the reversing methods are private
186         send(*a, &pr)
187       end
188     end
189   end
190 end

Private Instance Methods

add_column(*args) click to toggle source
    # File lib/sequel/extensions/migration.rb
194 def add_column(*args)
195   @actions << [:drop_column, args[0], args[1]]
196 end
add_index(*args) click to toggle source
    # File lib/sequel/extensions/migration.rb
198 def add_index(*args)
199   @actions << [:drop_index, *args]
200 end
alter_table(table, &block) click to toggle source
    # File lib/sequel/extensions/migration.rb
202 def alter_table(table, &block)
203   @actions << [:alter_table, table, MigrationAlterTableReverser.new.reverse(&block)]
204 end
create_enum(name, _) click to toggle source
    # File lib/sequel/extensions/pg_enum.rb
181 def create_enum(name, _)
182   @actions << [:drop_enum, name]
183 end
create_join_table(*args) click to toggle source
    # File lib/sequel/extensions/migration.rb
206 def create_join_table(*args)
207   @actions << [:drop_join_table, *args]
208 end
create_table(name, opts=OPTS) click to toggle source
    # File lib/sequel/extensions/migration.rb
210 def create_table(name, opts=OPTS)
211   @actions << [:drop_table, name, opts]
212 end
create_view(name, _, opts=OPTS) click to toggle source
    # File lib/sequel/extensions/migration.rb
214 def create_view(name, _, opts=OPTS)
215   @actions << [:drop_view, name, opts]
216 end
rename_column(table, name, new_name) click to toggle source
    # File lib/sequel/extensions/migration.rb
218 def rename_column(table, name, new_name)
219   @actions << [:rename_column, table, new_name, name]
220 end
rename_enum(old_name, new_name) click to toggle source
    # File lib/sequel/extensions/pg_enum.rb
185 def rename_enum(old_name, new_name)
186   @actions << [:rename_enum, new_name, old_name]
187 end
rename_table(table, new_name) click to toggle source
    # File lib/sequel/extensions/migration.rb
222 def rename_table(table, new_name)
223   @actions << [:rename_table, new_name, table]
224 end