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
11#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
12pub struct ForeignKeyDrift {
13    pub extension: String,
14    pub table: String,
15    pub constraint: String,
16    pub sql: String,
17    pub cause: String,
18}
19
20/// What `install_extension_schemas*` applied and what it could not.
21///
22/// `foreign_key_drift` is non-empty only for an established extension whose
23/// declarative foreign key cannot be created; the install still committed
24/// every other statement. A fresh database never reports drift — the same
25/// condition fails the install there.
26#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
27pub struct SchemaInstallReport {
28    pub foreign_key_drift: Vec<ForeignKeyDrift>,
29}
30
31impl SchemaInstallReport {
32    #[must_use]
33    pub const fn is_clean(&self) -> bool {
34        self.foreign_key_drift.is_empty()
35    }
36}