# Live migration: base copy under a replication slot, then logical
# replication until you approve the cutover. The follow prerequisites are
# strict; read docs/reference/prerequisites.md first, and see
# 06-live-superuser.yaml to have the preflight apply the grants itself.
# Runbook: docs/operations/live-migration.md.
apiVersion: pgcopydb-operator.io/v1beta1
kind: Migration
metadata:
  name: live-migration
spec:
  source:
    host: billing.example.com
    database: billing
    username: migrator  # MUST have the REPLICATION role attribute
    passwordSecretRef: {name: billing-source, key: password}
    sslMode: require
  target:
    host: billing-pg-rw.billing.svc
    database: billing
    # Needs EXECUTE on pg_replication_origin_* and (PG15+) GRANT SET ON
    # PARAMETER session_replication_role; see prerequisites.
    username: app
    passwordSecretRef: {name: billing-pg-app, key: password}
  follow:
    enabled: true
    # Defaults: plugin pgoutput; slot, origin, and publication names generated
    # per Migration, so several migrations can share one source instance.
    # maxCatchupLag: 16Mi  # lag under which the CaughtUp condition goes True
    # publication: billing_pub  # pre-created publication; skips create/drop rights
    # allowMissingReplicaIdentity: ["public.audit_log"]  # read-only tables only
  cutover:
    mode: Manual  # the default: stop writes to the source, then approve
    # approved: true  # arms cutover; confirmed catch-up starts the drain
    # mode: Automatic  # instead: cut over unattended once CaughtUp holds
  # suspend: true  # pauses between attempts; the slot keeps retaining WAL
  workVolume:
    # Holds the base-copy dumps AND the change stream: streamed changes
    # accumulate here for the whole migration window. Budget the clone's
    # needs plus write rate times the expected window.
    size: 50Gi
