Class: ActualDbSchema::Migration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/actual_db_schema/migration.rb

Overview

The Migration class is responsible for managing and retrieving migration information

Defined Under Namespace

Classes: Migration

Instance Method Summary collapse

Instance Method Details

#allObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/actual_db_schema/migration.rb', line 25

def all
  migrations = []

  MigrationContext.instance.each do |context|
    indexed_migrations = context.migrations.index_by { |m| m.version.to_s }

    context.migrations_status.each do |status, version|
      migration = indexed_migrations[version]
      migrations << build_migration_struct(status, migration) if should_include?(status, migration)
    end
  end

  sort_migrations_desc(migrations)
end

#all_phantomObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/actual_db_schema/migration.rb', line 10

def all_phantom
  migrations = []

  MigrationContext.instance.each do |context|
    indexed_migrations = context.phantom_migrations.index_by { |m| m.version.to_s }

    context.migrations_status.each do |status, version|
      migration = indexed_migrations[version]
      migrations << build_migration_struct(status, migration) if should_include?(status, migration)
    end
  end

  sort_migrations_desc(migrations)
end

#find(version, database) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/actual_db_schema/migration.rb', line 40

def find(version, database)
  MigrationContext.instance.each do |context|
    next unless ActualDbSchema.db_config[:database] == database

    migration = find_migration_in_context(context, version)
    return migration if migration
  end
  nil
end

#migrate(version, database) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/actual_db_schema/migration.rb', line 65

def migrate(version, database)
  MigrationContext.instance.each do |context|
    next unless ActualDbSchema.db_config[:database] == database

    if context.migrations.detect { |m| m.version.to_s == version }
      context.run(:up, version.to_i)
      break
    end
  end
end

#rollback(version, database) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/actual_db_schema/migration.rb', line 50

def rollback(version, database)
  MigrationContext.instance.each do |context|
    next unless ActualDbSchema.db_config[:database] == database

    if context.migrations.detect { |m| m.version.to_s == version }
      context.run(:down, version.to_i)
      break
    end
  end
end

#rollback_allObject



61
62
63
# File 'lib/actual_db_schema/migration.rb', line 61

def rollback_all
  MigrationContext.instance.each(&:rollback_branches)
end