From 2171b6d711840b69c240bda23b25fe36101e5bf5 Mon Sep 17 00:00:00 2001 From: Mane Darbinyan Date: Wed, 18 Dec 2024 12:39:03 +0400 Subject: [PATCH] Fix phantom migration rollback failures caused by cross-branch acronyms --- .../patches/migration_context.rb | 7 +++++ test/rake_task_test.rb | 27 +++++++++++++++++++ test/support/test_utils.rb | 6 +++++ 3 files changed, 40 insertions(+) diff --git a/lib/actual_db_schema/patches/migration_context.rb b/lib/actual_db_schema/patches/migration_context.rb index 6db97c1..df35bad 100644 --- a/lib/actual_db_schema/patches/migration_context.rb +++ b/lib/actual_db_schema/patches/migration_context.rb @@ -79,6 +79,8 @@ def show_info_for(migration) end def migrate(migration) + migration.name = extract_class_name(migration.filename) + message = "[ActualDbSchema] Rolling back phantom migration #{migration.version} #{migration.name} " \ "(from branch: #{branch_for(migration.version.to_s)})" puts colorize(message, :gray) @@ -89,6 +91,11 @@ def migrate(migration) File.delete(migration.filename) end + def extract_class_name(filename) + content = File.read(filename) + content.match(/^class\s+([A-Za-z0-9_]+)\s+