Module: ActualDbSchema::Patches::MigrationContext

Includes:
OutputFormatter
Defined in:
lib/actual_db_schema/patches/migration_context.rb

Overview

Add new command to roll back the phantom migrations

Constant Summary

Constants included from OutputFormatter

OutputFormatter::UNICODE_COLORS

Instance Method Summary collapse

Methods included from OutputFormatter

#colorize

Instance Method Details

#phantom_migrationsObject



23
24
25
26
27
28
29
30
31
# File 'lib/actual_db_schema/patches/migration_context.rb', line 23

def phantom_migrations
  paths = Array(migrations_paths)
  current_branch_files = Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
  current_branch_file_names = current_branch_files.map { |f| ActualDbSchema.migration_filename(f) }

  migrations.reject do |migration|
    current_branch_file_names.include?(ActualDbSchema.migration_filename(migration.filename))
  end
end

#rollback_branches(manual_mode: false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/actual_db_schema/patches/migration_context.rb', line 9

def rollback_branches(manual_mode: false)
  schemas = multi_tenant_schemas&.call || []
  schema_count = schemas.any? ? schemas.size : 1

  rolled_back_migrations = if schemas.any?
                             rollback_multi_tenant(schemas, manual_mode: manual_mode)
                           else
                             rollback_branches_for_schema(manual_mode: manual_mode)
                           end

  delete_migrations(rolled_back_migrations, schema_count)
  rolled_back_migrations.any?
end