Class: Pcrd::Commands::Status

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

Overview

Displays the current migration state from the checkpoint database and (optionally) queries the live replication slot for current lag.

Reads entirely from local state (checkpoint SQLite) so it works without an active connection to source or target. If source is reachable, also shows live replication lag and estimated time to cutover readiness.

Constant Summary collapse

PASTEL =
Pastel.new
PHASE_LABELS =
{
  new:       "not started",
  backfill:  "backfill in progress",
  streaming: "streaming (catchup phase)",
  cutover:   "cutover complete"
}.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Status.



23
24
25
26
# File 'lib/pcrd/commands/status.rb', line 23

def initialize(config, options = {})
  @config  = config
  @options = Options.normalize(options)
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pcrd/commands/status.rb', line 28

def run
  checkpoint_path = @config.migrate&.checkpoint_db || "./pcrd_checkpoint.sqlite3"

  unless File.exist?(checkpoint_path)
    puts
    puts "  #{PASTEL.yellow("No checkpoint found at #{checkpoint_path}")}"
    puts "  Run `pcrd migrate` to start the migration."
    puts
    return
  end

  store = Checkpoint::Store.new(checkpoint_path)
  print_status(store)
  store.close
end