Class: PgSqlTriggers::Migrator::PreApplyComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_sql_triggers/migrator/pre_apply_comparator.rb

Overview

Pre-apply comparator that extracts expected SQL from migrations and compares it with the current database state. rubocop:disable Metrics/ClassLength – all SQL parsing + diffing lives here so the two halves (parse migration SQL -> expected state, diff against actual) stay co-located.

Class Method Summary collapse

Class Method Details

.compare(migration_instance, direction: :up) ⇒ Object

Compare expected state from migration with actual database state Returns a comparison result with diff information



15
16
17
18
# File 'lib/pg_sql_triggers/migrator/pre_apply_comparator.rb', line 15

def compare(migration_instance, direction: :up)
  captured_sql = capture_sql(migration_instance, direction)
  compare_sql(captured_sql)
end

.compare_sql(captured_sql) ⇒ Object

Compare using pre-captured SQL (avoids re-instantiating the migration class). Returns a comparison result with diff information.



22
23
24
25
26
# File 'lib/pg_sql_triggers/migrator/pre_apply_comparator.rb', line 22

def compare_sql(captured_sql)
  expected = parse_sql_to_state(captured_sql)
  actual = extract_actual_state(expected)
  generate_diff(expected, actual)
end