Class: PgSqlTriggers::Migrator::PreApplyDiffReporter

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

Overview

Formats pre-apply comparison results into human-readable diff reports

Class Method Summary collapse

Class Method Details

.format(diff_result, migration_name: nil) ⇒ Object

Format diff result as a string report



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pg_sql_triggers/migrator/pre_apply_diff_reporter.rb', line 9

def format(diff_result, migration_name: nil)
  return "No differences detected. Migration is safe to apply." unless diff_result[:has_differences]

  output = []
  output << ("=" * 80)
  output << "Pre-Apply Comparison Report"
  output << "Migration: #{migration_name}" if migration_name
  output << ("=" * 80)
  output << ""

  # Report on functions
  if diff_result[:functions].any?
    output << "Functions:"
    output << ("-" * 80)
    diff_result[:functions].each do |func_diff|
      output.concat(format_function_diff(func_diff))
      output << ""
    end
  end

  # Report on triggers
  if diff_result[:triggers].any?
    output << "Triggers:"
    output << ("-" * 80)
    diff_result[:triggers].each do |trigger_diff|
      output.concat(format_trigger_diff(trigger_diff))
      output << ""
    end
  end

  # Report on drops (for down migrations)
  if diff_result[:drops]&.any?
    output << "Drops:"
    output << ("-" * 80)
    diff_result[:drops].each do |drop|
      output << "  - Will #{drop[:type] == :trigger ? 'drop trigger' : 'drop function'}: #{drop[:name]}"
    end
    output << ""
  end

  output << ("=" * 80)
  output << ""
  output << "⚠️  WARNING: This migration will modify existing database objects."
  output << "Review the differences above before proceeding."

  output.join("\n")
end

.format_summary(diff_result) ⇒ Object

Format a concise summary for console output



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pg_sql_triggers/migrator/pre_apply_diff_reporter.rb', line 58

def format_summary(diff_result)
  return "✓ No differences - safe to apply" unless diff_result[:has_differences]

  summary = []
  summary << "⚠️  Differences detected:"

  new_count = diff_result[:functions].count { |f| f[:status] == :new } +
              diff_result[:triggers].count { |t| t[:status] == :new }
  modified_count = diff_result[:functions].count { |f| f[:status] == :modified } +
                   diff_result[:triggers].count { |t| t[:status] == :modified }

  summary << "  - #{new_count} new object(s) will be created"
  summary << "  - #{modified_count} existing object(s) will be modified"

  summary.join("\n")
end