Module: Torque::PostgreSQL::VersionedCommands::MigrationContext

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

Constant Summary collapse

InvalidMigrationTimestampError =
ActiveRecord::InvalidMigrationTimestampError
PGAdapter =
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Instance Method Summary collapse

Instance Method Details

#migration_commandsObject



57
58
59
# File 'lib/torque/postgresql/versioned_commands/migration_context.rb', line 57

def migration_commands
  migrations.select { |m| m.is_a?(VersionedCommands::CommandMigration) }
end

#migrationsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/torque/postgresql/versioned_commands/migration_context.rb', line 21

def migrations
  return super unless running_for_pg?

  commands = command_files.map do |file|
    version, op, type, name, op_version, scope = parse_command_filename(file)
    raise IllegalCommandTypeError.new(file) unless version
    if validate_timestamp? && !valid_migration_timestamp?(version)
      raise InvalidMigrationTimestampError.new(version, [op, type, name, op_version].join('_'))
    end

    version = version.to_i
    CommandMigration.new(file, version, op, type, name, op_version.to_i, scope)
  end

  super.concat(commands).sort_by(&:version)
end

#migrations_statusObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/torque/postgresql/versioned_commands/migration_context.rb', line 38

def migrations_status
  return super unless running_for_pg?
  db_list = schema_migration.normalized_versions

  commands = command_files.map do |file|
    version, op, type, name, op_version, scope = parse_command_filename(file)
    raise IllegalCommandTypeError.new(file) unless version
    if validate_timestamp? && !valid_migration_timestamp?(version)
      raise InvalidMigrationTimestampError.new(version, [op, type, name, op_version].join('_'))
    end

    version = schema_migration.normalize_migration_number(version)
    status = db_list.delete(version) ? "up" : "down"
    [status, version, "#{op.capitalize} #{type.capitalize} #{name}#{scope} (v#{op_version})"]
  end

  (commands + super).uniq(&:second).sort_by(&:second)
end