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 begin 190 instance_exec(&block) 191 rescue 192 just_raise = true 193 end 194 if just_raise 195 Proc.new{raise Sequel::Error, "irreversible migration method used in #{block.source_location.first}, you may need to write your own down method"} 196 else 197 actions = @actions.reverse 198 Proc.new do 199 actions.each do |a| 200 pr = a.last.is_a?(Proc) ? a.pop : nil 201 # Allow calling private methods as the reversing methods are private 202 send(*a, &pr) 203 end 204 end 205 end 206 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 210 def add_column(*args) 211 @actions << [:drop_column, args[0], args[1]] 212 end
Source
# File lib/sequel/extensions/migration.rb 214 def add_index(*args) 215 @actions << [:drop_index, *args] 216 end
Source
# File lib/sequel/extensions/migration.rb 218 def alter_table(table, &block) 219 @actions << [:alter_table, table, MigrationAlterTableReverser.new.reverse(&block)] 220 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 222 def create_join_table(*args) 223 @actions << [:drop_join_table, *args] 224 end
Source
# File lib/sequel/extensions/migration.rb 226 def create_table(name, opts=OPTS, &_) 227 @actions << [:drop_table, name, opts] 228 end
Source
# File lib/sequel/extensions/migration.rb 230 def create_view(name, _, opts=OPTS) 231 @actions << [:drop_view, name, opts] 232 end
Source
# File lib/sequel/extensions/migration.rb 234 def rename_column(table, name, new_name) 235 @actions << [:rename_column, table, new_name, name] 236 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 238 def rename_table(table, new_name) 239 @actions << [:rename_table, new_name, table] 240 end