Skip to content

symfonic.cli.postgres_edge_preflight

postgres_edge_preflight

Operator CLI for the read-only PostgreSQL edge-index preflight.

MissingPostgresDependency

Bases: RuntimeError

The optional PostgreSQL driver is not installed.

postgres_edge_preflight

postgres_edge_preflight(schema: Annotated[str, Option('--schema', help='Schema containing memory_edges.')]) -> None

Print index metadata and edge counts; never authorize the migration.

Source code in src/symfonic/cli/postgres_edge_preflight.py
def postgres_edge_preflight(
    schema: Annotated[str, typer.Option("--schema", help="Schema containing memory_edges.")],
) -> None:
    """Print index metadata and edge counts; never authorize the migration."""
    dsn = os.environ.get("POSTGRES_DSN")
    if not dsn:
        typer.echo(
            json.dumps({"status": "ERROR", "reason": "POSTGRES_DSN is required"}),
            err=True,
        )
        raise typer.Exit(2)
    try:
        report = asyncio.run(asyncio.wait_for(_inspect(dsn, schema), timeout=30))
    except MissingPostgresDependency:
        typer.echo(
            json.dumps({"status": "ERROR", "reason": "install symfonic-core[postgres]"}),
            err=True,
        )
        raise typer.Exit(2) from None
    except Exception:
        # Driver exceptions can contain connection strings and SQL values.
        typer.echo(json.dumps({"status": "ERROR", "reason": "preflight failed"}), err=True)
        raise typer.Exit(2) from None
    typer.echo(
        json.dumps(
            {
                "status": "INSPECTED",
                "indexes": [asdict(index) for index in report.indexes],
                "old_index_present": report.old_index_present,
                "new_index_present": report.new_index_present,
                "null_scope_rows": report.null_scope_rows,
                "duplicate_effective_owner_groups": report.duplicate_effective_owner_groups,
                "sibling_tuple_groups": report.sibling_tuple_groups,
                "fleet_writer_state": report.fleet_writer_state,
                "migration_authorized": report.migration_authorized,
            },
            sort_keys=True,
        )
    )