no-mistakes-postgres-engine 0.109.129

PostgreSQL embedded SQL extraction, schema catalog, and replay-safety analysis for no-mistakes
Documentation
use super::snapshot::Snapshot;
use anyhow::{bail, Result};

const HINT: &str = "generate the catalog with `no-mistakes postgres catalog`";

pub(super) fn jsonc_parse_options() -> jsonc_parser::ParseOptions {
    jsonc_parser::ParseOptions {
        allow_comments: true,
        allow_loose_object_property_names: false,
        allow_trailing_commas: false,
        allow_missing_commas: false,
        allow_single_quoted_strings: false,
        allow_hexadecimal_numbers: false,
        allow_unary_plus_numbers: false,
        allow_bare_decimal_point_numbers: false,
        allow_extended_string_escapes: false,
        allow_non_finite_numbers: false,
    }
}

/// Read the single catalog format that `no-mistakes postgres catalog` writes.
pub(super) fn parse_snapshot(path: &str, value: serde_json::Value) -> Result<Snapshot> {
    if value
        .get("formatVersion")
        .and_then(serde_json::Value::as_u64)
        != Some(2)
    {
        bail!(
            "schemaCatalogPath {path} must be a no-mistakes schema catalog with formatVersion 2; {HINT}"
        );
    }
    serde_path_to_error::deserialize(value).map_err(|error| {
        let field = error.path().to_string();
        let message = error.inner();
        if field == "." {
            anyhow::anyhow!("schemaCatalogPath {path} has an invalid schema: {message}; {HINT}")
        } else {
            anyhow::anyhow!(
                "schemaCatalogPath {path} has an invalid schema: {field}: {message}; {HINT}"
            )
        }
    })
}