Skip to main content

systemprompt_database/lifecycle/installation/
report.rs

1//! Outcome of a schema installation that succeeded but left typed drift
2//! behind: a declared foreign key an established database could not create.
3//! Callers surface the report — health endpoints, `infra db migrate` — rather
4//! than reading it from the log.
5//!
6//! Copyright (c) systemprompt.io — Business Source License 1.1.
7//! See <https://systemprompt.io> for licensing details.
8
9use serde::Serialize;
10
11use super::undeclared::SchemaResidue;
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
14pub struct ForeignKeyDrift {
15    pub extension: String,
16    pub table: String,
17    pub constraint: String,
18    pub sql: String,
19    pub cause: String,
20}
21
22/// What `install_extension_schemas*` applied and what it could not.
23///
24/// `foreign_key_drift` is non-empty only for an established extension whose
25/// declarative foreign key cannot be created; the install still committed
26/// every other statement. A fresh database never reports drift — the same
27/// condition fails the install there. `residue` is what the database holds
28/// that no registered extension declares (tables and migration ledgers a
29/// deleted crate left behind); it never fails an install and is reported so
30/// a drop migration can be written.
31#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
32pub struct SchemaInstallReport {
33    pub foreign_key_drift: Vec<ForeignKeyDrift>,
34    pub residue: SchemaResidue,
35}
36
37impl SchemaInstallReport {
38    #[must_use]
39    pub const fn is_clean(&self) -> bool {
40        self.foreign_key_drift.is_empty()
41    }
42
43    #[must_use]
44    pub const fn is_tidy(&self) -> bool {
45        self.residue.is_empty()
46    }
47}