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§
- Analysis
Outcome - Immutable analysis result with API-owned snapshots and built-in renderers.
- Baseline
- Opaque, validated database baseline used for analysis.
- Baseline
Contents - Redacted object counts contained in a baseline.
- Baseline
Coverage - Catalog families and schema scope represented by a baseline.
- Baseline
Inspection - Redacted baseline inspection suitable for display or serialization.
- Baseline
Report - Redacted baseline context included in every machine-readable report.
- Cache
Key - Validated 256-bit key for encrypted baseline caches.
- Config
- Complete safe-migrate configuration.
- Database
Url - Validated PostgreSQL connection input for embedded synchronization.
- Error
- Error returned by the supported API.
- Evidence
- Stable explanation for a conservative analysis decision.
- Evidence
Location - Location of conservative-analysis evidence.
- Finding
- A source-aware, machine-readable migration finding.
- Finding
Summary - Counts of findings by severity tier.
- Migration
- One named SQL migration in its intended analysis order.
- Observed
Settings - Session settings observed while synchronizing a baseline.
- Rule
- Descriptor and effective configuration of one primary rule.
- Rule
Config - Per-rule configuration accepted by
safe-migrate.toml. - Source
Location - One-based source position of a finding.
Enums§
- Auto
Sync Status - Result of an optional caller-managed baseline refresh.
- Baseline
Schema Scope - Schema scope captured when the baseline was synchronized.
- Baseline
Status - Availability of the baseline used for an analysis.
- Confidence
- Confidence in the final migration result.
- Error
Kind - Broad category of a supported API failure.
- Evidence
Code - Stable reason why analysis had to be conservative.
- Evidence
Scope - Whether evidence affects one statement or the entire migration chain.
- Object
Kind - Stable category of the database object associated with a finding.
- Operation
Kind - Stable category of the SQL operation that produced a finding.
- Rule
Configuration Field - 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.