Skip to main content

Module api

Module api 

Source
Expand description

Supported Rust API for configuration, synchronization, and analysis. Stable, supported Rust API for safe-migrate.

The public API deliberately owns its configuration, baseline, and report types. The analyzer implementation and its mutable schema model remain crate-private implementation details.

use safe_migrate::api::{self, Baseline, Config};
use std::path::Path;

let config = Config::load_from_file(Path::new("safe-migrate.toml"))?;
let baseline = Baseline::load_optional(Path::new(".safe-migrate.cache"), &config)?;
let outcome = api::analyze(&config, "001.sql", "CREATE TABLE users (id bigint);", &baseline)?;
if outcome.should_halt() {
    eprintln!("{}", outcome.markdown());
}
// Internal state-machine types are intentionally not a downstream API.
use safe_migrate::_internal::analysis::state::AnalysisState;

Analysis outcomes preserve their internal reporting invariants:

let config = Config::default();
let baseline = Baseline::unavailable();
let mut outcome = api::analyze(&config, "001.sql", "", &baseline)?;
outcome.findings.clear();

Structs§

AnalysisOutcome
Immutable analysis result with API-owned snapshots and built-in renderers.
Baseline
Opaque, validated database baseline used for analysis.
BaselineContents
Redacted object counts contained in a baseline.
BaselineCoverage
Catalog families and schema scope represented by a baseline.
BaselineInspection
Redacted baseline inspection suitable for display or serialization.
BaselineReport
Redacted baseline context included in every machine-readable report.
CacheKey
Validated 256-bit key for encrypted baseline caches.
Config
Complete safe-migrate configuration.
DatabaseUrl
Validated PostgreSQL connection input for embedded synchronization.
Error
Error returned by the supported API.
Evidence
Stable explanation for a conservative analysis decision.
EvidenceLocation
Location of conservative-analysis evidence.
Finding
A source-aware, machine-readable migration finding.
FindingSummary
Counts of findings by severity tier.
Migration
One named SQL migration in its intended analysis order.
ObservedSettings
Session settings observed while synchronizing a baseline.
Rule
Descriptor and effective configuration of one primary rule.
RuleConfig
Per-rule configuration accepted by safe-migrate.toml.
SourceLocation
One-based source position of a finding.

Enums§

AutoSyncStatus
Result of an optional caller-managed baseline refresh.
BaselineSchemaScope
Schema scope captured when the baseline was synchronized.
BaselineStatus
Availability of the baseline used for an analysis.
Confidence
Confidence in the final migration result.
ErrorKind
Broad category of a supported API failure.
EvidenceCode
Stable reason why analysis had to be conservative.
EvidenceScope
Whether evidence affects one statement or the entire migration chain.
ObjectKind
Stable category of the database object associated with a finding.
OperationKind
Stable category of the SQL operation that produced a finding.
RuleConfigurationField
Configuration field supported by an individual rule.
Tier
Stable severity assigned to a finding.
Verdict
Overall deployment verdict derived from all findings.

Constants§

REPORT_SCHEMA_VERSION
Current schema version emitted by AnalysisOutcome::json.

Functions§

analyze
Analyze a single migration against an opaque baseline.
analyze_chain
Analyze an ordered migration chain against an opaque baseline.
rule
Look up one primary rule and include its effective configuration.
rules
Return every primary rule with its effective configuration.
sync
Synchronize PostgreSQL metadata into a cache that can later be loaded as a Baseline.
sync_with_secrets
Synchronize PostgreSQL metadata using caller-owned secret material.
validate_config
Validate configuration against the rule catalog and sync settings.