Sha256: 68d7bea4d8c0a84437171a59ef4cf32cd3bd8818661da920019b999646a4c603

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

module ActiveRecord
  module PGCollation
    register :command_recorder do
      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_collation(*args, &block)
        record(:create_collation, args, &block)
      end

      def create_collation_from(*args, &block)
        record(:create_collation_from, args, &block)
      end

      private

      def invert_create_collation(args)
        [:drop_collation, args]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-pg_collation-0.1.2 lib/active_record/pg_collation/command_recorder.rb
activerecord-pg_collation-0.1.1 lib/active_record/pg_collation/command_recorder.rb
activerecord-pg_collation-0.1.0 lib/active_record/pg_collation/command_recorder.rb