Sha256: e656dee13851d2de6b1e13b977c798c9969bf631de110eea6f46a502faac68eb
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
module ActiveRecord module PGEnum def self.install_command_recorder require "active_record/migration/command_recorder" ActiveRecord::Migration::CommandRecorder.include CommandRecorder end # ActiveRecord::Migration::CommandRecorder is a class used by reversible migrations. # It captures the forward migration commands and translates them into their inverse # by way of some simple metaprogramming. # # The Migrator class uses CommandRecorder during the reverse migration instead of # the connection object. Forward migration calls are translated to their inverse # where possible, and then forwarded to the connetion. Irreversible migrations # raise an exception. # # Known schema statement methods are metaprogrammed into an inverse method like so: # # create_table => invert_create_table # # which returns: # # [:drop_table, args.first] module CommandRecorder def create_enum(*args, &block) record(:create_enum, args, &block) end def drop_enum(*args, &block) record(:drop_enum, args, &block) end def add_enum_value(*args, &block) record(:add_enum_value, args, &block) end private def invert_create_enum(args) [:drop_enum, args] end def invert_drop_enum(args) raise ActiveRecord::IrreversibleMigration, "drop_enum is only reversible if given a list of values" unless args.length > 1 [:create_enum, args] end def invert_add_enum_value(args) raise ActiveRecord::IrreversibleMigration, "ENUM values cannot be removed once added. Drop and Replace it instead at your own risk." end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-pg_enum-0.4.0 | lib/active_record/pg_enum/command_recorder.rb |