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.
:nocov:
Public Class Methods
Source
# File lib/sequel/extensions/migration.rb 181 def initialize 182 @actions = [] 183 end
Public Instance Methods
Source
# File lib/sequel/extensions/migration.rb 188 def reverse(&block) 189 instance_exec(&block) 190 rescue NoMethodError => e 191 Proc.new{raise Sequel::Error, "irreversible migration method \"#{e.name}\" used in #{block.source_location.first}, you may need to write your own down method"} 192 rescue => e 193 Proc.new{raise Sequel::Error, "unable to reverse migration due to #{e.class} in #{block.source_location.first}, you may need to write your own down method"} 194 else 195 actions = @actions.reverse 196 Proc.new do 197 actions.each do |a| 198 pr = a.last.is_a?(Proc) ? a.pop : nil 199 # Allow calling private methods as the reversing methods are private 200 send(*a, &pr) 201 end 202 end 203 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.
Private Instance Methods
Source
# File lib/sequel/extensions/migration.rb 207 def add_column(*args) 208 @actions << [:drop_column, args[0], args[1]] 209 end
Source
# File lib/sequel/extensions/migration.rb 211 def add_index(*args) 212 @actions << [:drop_index, *args] 213 end
Source
# File lib/sequel/extensions/migration.rb 215 def alter_table(table, &block) 216 @actions << [:alter_table, table, MigrationAlterTableReverser.new.reverse(&block)] 217 end
Source
# File lib/sequel/extensions/pg_enum.rb 188 def create_enum(name, _) 189 @actions << [:drop_enum, name] 190 end
Source
# File lib/sequel/extensions/migration.rb 219 def create_join_table(*args) 220 @actions << [:drop_join_table, *args] 221 end
Source
# File lib/sequel/extensions/migration.rb 223 def create_table(name, opts=OPTS, &_) 224 @actions << [:drop_table, name, opts] 225 end
Source
# File lib/sequel/extensions/migration.rb 227 def create_view(name, _, opts=OPTS) 228 @actions << [:drop_view, name, opts] 229 end
Source
# File lib/sequel/extensions/migration.rb 231 def rename_column(table, name, new_name) 232 @actions << [:rename_column, table, new_name, name] 233 end
Source
# File lib/sequel/extensions/pg_enum.rb 192 def rename_enum(old_name, new_name) 193 @actions << [:rename_enum, new_name, old_name] 194 end
Source
# File lib/sequel/extensions/migration.rb 235 def rename_table(table, new_name) 236 @actions << [:rename_table, new_name, table] 237 end