Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.
# File lib/sequel/extensions/migration.rb, line 158 def initialize @actions = [] end
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, line 165 def reverse(&block) begin instance_eval(&block) rescue just_raise = true end if just_raise Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'} else actions = @actions.reverse Proc.new do actions.each do |a| if a.last.is_a?(Proc) pr = a.pop send(*a, &pr) else send(*a) end end end end end
# File lib/sequel/extensions/migration.rb, line 190 def add_column(*args) @actions << [:drop_column, args[0], args[1]] end
# File lib/sequel/extensions/migration.rb, line 194 def add_index(*args) @actions << [:drop_index, *args] end
# File lib/sequel/extensions/migration.rb, line 198 def alter_table(table, &block) @actions << [:alter_table, table, MigrationAlterTableReverser.new.reverse(&block)] end
# File lib/sequel/extensions/migration.rb, line 202 def create_join_table(*args) @actions << [:drop_join_table, *args] end
# File lib/sequel/extensions/migration.rb, line 206 def create_table(name, opts=OPTS) @actions << [:drop_table, name, opts] end
# File lib/sequel/extensions/migration.rb, line 210 def create_view(name, _, opts=OPTS) @actions << [:drop_view, name, opts] end
# File lib/sequel/extensions/migration.rb, line 214 def rename_column(table, name, new_name) @actions << [:rename_column, table, new_name, name] end
# File lib/sequel/extensions/migration.rb, line 218 def rename_table(table, new_name) @actions << [:rename_table, new_name, table] end