Module: PostgreSQLAdapterExtensions::CommandRecorder

Defined in:
lib/postgresql_adapter_extensions/command_recorder.rb

Overview

Module that extends ActiveRecord’s CommandRecorder to handle sequence-related commands.

This module is designed to work with reversible migrations in ActiveRecord, specifically to manage PostgreSQL sequence operations. The methods capture forward migration commands for sequences and generate their inverse using simple metaprogramming.

This will create a sequence, and during rollback, it will drop the sequence.

Examples:

class AddSomeSequence < ActiveRecord::Migration[6.0]
  def change
    create_sequence :some_sequence
  end
end

See Also:

  • ActiveRecord::Migration::CommandRecorder

Author:

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#alter_sequence(*args, &block) ⇒ void

This method returns an undefined value.

Records the alteration of a PostgreSQL sequence during a migration.

This method is invoked when altering a sequence in the database. The corresponding inverse operation is not possible, so it will raise an error during rollback.

Parameters:

  • args (Array)

    Arguments required to alter the sequence.

  • block (Proc)

    An optional block passed to the command.

Raises:

  • (ActiveRecord::IrreversibleMigration)

    When attempting to rollback an altered sequence.

Author:

Since:

  • 1.0.0



58
59
60
# File 'lib/postgresql_adapter_extensions/command_recorder.rb', line 58

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

#create_sequence(*args, &block) ⇒ void

This method returns an undefined value.

Records the creation of a PostgreSQL sequence during a migration.

This method is invoked when creating a sequence in the database. The corresponding inverse operation will be to drop the sequence during rollback.

Parameters:

  • args (Array)

    Arguments required to create the sequence (usually the sequence name).

  • block (Proc)

    An optional block passed to the command.

Author:

Since:

  • 1.0.0



40
41
42
# File 'lib/postgresql_adapter_extensions/command_recorder.rb', line 40

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

#drop_sequence(*args, &block) ⇒ void

This method returns an undefined value.

Records the dropping of a PostgreSQL sequence during a migration.

This method is invoked when dropping a sequence from the database. The corresponding inverse operation is not possible, so it will raise an error during rollback.

Parameters:

  • args (Array)

    Arguments required to drop the sequence (usually the sequence name).

  • block (Proc)

    An optional block passed to the command.

Raises:

  • (ActiveRecord::IrreversibleMigration)

    When attempting to rollback a dropped sequence.

Author:

Since:

  • 1.0.0



76
77
78
# File 'lib/postgresql_adapter_extensions/command_recorder.rb', line 76

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

#rename_sequence(*args) ⇒ void

This method returns an undefined value.

Records the renaming of a PostgreSQL sequence during a migration.

This method is invoked when renaming a sequence in the database. The corresponding inverse operation will be to rename the sequence back to its original name during rollback.

Parameters:

  • args (Array)

    Arguments required to rename the sequence (usually the old and new sequence names).

Since:

  • 1.2.0



93
94
95
# File 'lib/postgresql_adapter_extensions/command_recorder.rb', line 93

def rename_sequence(*args)
  record(:rename_sequence, args)
end