Class: Pcrd::Preflight

Inherits:
Object
  • Object
show all
Defined in:
lib/pcrd/preflight.rb

Overview

Runs all pre-migration safety checks and generates the target DDL.

Checks are grouped and run top-to-bottom. Connection failures are hard stops (subsequent checks that need a connection are skipped). All table checks run even when earlier tables fail, so the operator sees all problems at once.

Returns a Result that includes all check items and a DDL map for display.

Defined Under Namespace

Classes: Item, Result

Constant Summary collapse

HARD_FAIL =

ddl_map: Hash<table_name, String> — generated CREATE TABLE SQL per table row_counts: Hash<table_name, Integer> — estimated row counts

:fail

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}) ⇒ Preflight

any :fail in items means Result#passed = false



24
25
26
27
28
29
30
# File 'lib/pcrd/preflight.rb', line 24

def initialize(config, options = {})
  @config  = config
  @options = Options.normalize(options)
  @items   = []
  @ddl_map = {}
  @row_counts = {}
end

Instance Method Details

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pcrd/preflight.rb', line 32

def run
  @source_pool = open_pool(@config.source)
  @target_pool = @config.target ? open_pool(@config.target) : nil

  check_source_connection
  check_target_connection
  check_wal_level
  check_replication_slots
  check_replication_objects

  (@config.migrate&.tables || []).each { |t| check_table(t) }

  Result.new(
    passed:     @items.none? { |i| i.status == :fail },
    items:      @items,
    ddl_map:    @ddl_map,
    row_counts: @row_counts
  )
ensure
  @source_pool&.close
  @target_pool&.close
end