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, line 158 def initialize @actions = [] 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, 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
Private Instance Methods
add_column(*args)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 190 def add_column(*args) @actions << [:drop_column, args[0], args[1]] end
add_index(*args)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 194 def add_index(*args) @actions << [:drop_index, *args] end
alter_table(table, &block)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 198 def alter_table(table, &block) @actions << [:alter_table, table, MigrationAlterTableReverser.new.reverse(&block)] end
create_enum(name, _)
click to toggle source
# File lib/sequel/extensions/pg_enum.rb, line 148 def create_enum(name, _) @actions << [:drop_enum, name] end
create_join_table(*args)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 202 def create_join_table(*args) @actions << [:drop_join_table, *args] end
create_table(name, opts=OPTS)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 206 def create_table(name, opts=OPTS) @actions << [:drop_table, name, opts] end
create_view(name, _, opts=OPTS)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 210 def create_view(name, _, opts=OPTS) @actions << [:drop_view, name, opts] end
rename_column(table, name, new_name)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 214 def rename_column(table, name, new_name) @actions << [:rename_column, table, new_name, name] end
rename_table(table, new_name)
click to toggle source
# File lib/sequel/extensions/migration.rb, line 218 def rename_table(table, new_name) @actions << [:rename_table, new_name, table] end