Module: Torque::PostgreSQL::VersionedCommands::Migrator

Defined in:
lib/torque/postgresql/versioned_commands/migrator.rb

Instance Method Summary collapse

Instance Method Details

#execute_migration_in_transaction(migration) ⇒ Object



7
8
9
10
11
12
# File 'lib/torque/postgresql/versioned_commands/migrator.rb', line 7

def execute_migration_in_transaction(migration)
  @versioned_command = versioned_command?(migration) && migration
  super
ensure
  @versioned_command = false
end

#record_version_state_after_migrating(version) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/torque/postgresql/versioned_commands/migrator.rb', line 14

def record_version_state_after_migrating(version)
  return super if (command = @versioned_command) == false

  @versioned_table ||= VersionedCommands::SchemaTable.new(connection.pool)
  @versioned_counter ||= @versioned_table.count

  if down?
    @versioned_counter -= 1
    @versioned_table.delete_version(command)
    @versioned_table.drop_table if @versioned_counter.zero?
  else
    @versioned_table.create_table if @versioned_counter.zero?
    @versioned_table.create_version(command)
    @versioned_counter += 1
  end
end

#versioned_command?(migration) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/torque/postgresql/versioned_commands/migrator.rb', line 31

def versioned_command?(migration)
  migration.is_a?(VersionedCommands::CommandMigration)
end