Class: ActualDbSchema::Migration
- Inherits:
-
Object
- Object
- ActualDbSchema::Migration
- 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
- #all ⇒ Object
- #all_phantom ⇒ Object
- #broken_versions ⇒ Object
- #delete(version, database) ⇒ Object
- #delete_all ⇒ Object
- #find(version, database) ⇒ Object
- #migrate(version, database) ⇒ Object
- #rollback(version, database) ⇒ Object
- #rollback_all ⇒ Object
Instance Method Details
#all ⇒ Object
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_phantom ⇒ Object
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 |
#broken_versions ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/actual_db_schema/migration.rb', line 76 def broken_versions broken = [] MigrationContext.instance.each do |context| context.migrations_status.each do |status, version, name| next unless name == "********** NO FILE **********" broken << Migration.new( status: status, version: version.to_s, name: name, branch: branch_for(version), database: ActualDbSchema.db_config[:database] ) end end broken end |
#delete(version, database) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/actual_db_schema/migration.rb', line 95 def delete(version, database) validate_broken_migration(version, database) MigrationContext.instance.each do next if database && ActualDbSchema.db_config[:database] != database next if ActiveRecord::Base.connection.select_values("SELECT version FROM schema_migrations").exclude?(version) ActiveRecord::Base.connection.execute("DELETE FROM schema_migrations WHERE version = '#{version}'") break end end |
#delete_all ⇒ Object
107 108 109 110 111 |
# File 'lib/actual_db_schema/migration.rb', line 107 def delete_all broken_versions.each do |version| delete(version.version, version.database) end 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_all ⇒ Object
61 62 63 |
# File 'lib/actual_db_schema/migration.rb', line 61 def rollback_all MigrationContext.instance.each(&:rollback_branches) end |