Cerbero.Snapshot.Exporter (cerbero v0.1.0)

Copy Markdown View Source

Builds a raw snapshot map from a live connection (or a DBA-returned file). Session is read-only with a short statement_timeout — defense in depth, not the privacy mechanism (that is the Queries allowlist).

CRDB row-count honesty: crdb_internal.table_row_statistics.estimated_row_count reads a literal 0 (not NULL) for a table with no propagated statistics yet — see crdb_row_counts/2 and Queries's moduledoc note for the full reasoning. A 0 is mapped to nil here, never forwarded as a real row count, so Cerbero.Catalog.scale/2 reads it as unknown (unbounded), never a fabricated zero.

Summary

Functions

A psql script: each query wrapped so output is JSON-lines per section. Works against both engines — CRDB speaks pgwire and supports COPY (SELECT row_to_json(...)) TO STDOUT (verified on v25.1), so the same psql mechanism serves the DBA path there with the CRDB-branched section list.

Rebuild a raw snapshot map from the DBA-returned psql output.

Functions

emit_sql(engine \\ "postgres")

@spec emit_sql(String.t()) :: String.t()

A psql script: each query wrapped so output is JSON-lines per section. Works against both engines — CRDB speaks pgwire and supports COPY (SELECT row_to_json(...)) TO STDOUT (verified on v25.1), so the same psql mechanism serves the DBA path there with the CRDB-branched section list.

export(url, opts \\ [])

@spec export(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

from_file(path, opts \\ [])

@spec from_file(
  Path.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Rebuild a raw snapshot map from the DBA-returned psql output.