Handles the reversing of reversible migrations. Basically records supported methods calls, translates them to reversed calls, and returns them in reverse order.
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 156 156: def reverse(&block) 157: begin 158: instance_eval(&block) 159: rescue 160: just_raise = true 161: end 162: if just_raise 163: Proc.new{raise Sequel::Error, 'irreversible migration method used, you may need to write your own down method'} 164: else 165: actions = @actions.reverse 166: Proc.new do 167: actions.each do |a| 168: if a.last.is_a?(Proc) 169: pr = a.pop 170: send(*a, &pr) 171: else 172: send(*a) 173: end 174: end 175: end 176: end 177: end
# File lib/sequel/extensions/migration.rb, line 181 181: def add_column(*args) 182: @actions << [:drop_column, args[0], args[1]] 183: end
# File lib/sequel/extensions/migration.rb, line 185 185: def add_index(*args) 186: @actions << [:drop_index, *args] 187: end
# File lib/sequel/extensions/migration.rb, line 189 189: def alter_table(table, &block) 190: @actions << [:alter_table, table, MigrationAlterTableReverser.new.reverse(&block)] 191: end
# File lib/sequel/extensions/migration.rb, line 193 193: def create_join_table(*args) 194: @actions << [:drop_join_table, *args] 195: end
# File lib/sequel/extensions/migration.rb, line 197 197: def create_table(*args) 198: @actions << [:drop_table, args.first] 199: end
# File lib/sequel/extensions/migration.rb, line 201 201: def create_view(*args) 202: @actions << [:drop_view, args.first] 203: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.