yang_base/database/schema_sync/
mod.rs1mod inspect;
9mod model;
10mod plan;
11mod preflight;
12mod render;
13mod sync;
14
15#[cfg(test)]
16mod __tests__;
17
18#[cfg(test)]
19pub(super) use model::{ExistingIndex, ExistingTableSchema};
20#[cfg(test)]
21pub(super) use plan::plan_table_sync;
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25#[non_exhaustive]
26pub enum SchemaSyncChangeKind {
27 CreatedTable,
29 AddedColumn,
31 RenamedColumn,
33 ModifiedColumn,
35 AddedPrimaryKey,
37 AddedIndex,
39 AddedCheck,
41 AddedForeignKey,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
47#[non_exhaustive]
48pub struct SchemaSyncChange {
49 pub table: String,
51 pub object: String,
53 pub kind: SchemaSyncChangeKind,
55}
56
57#[derive(Debug, Clone, Default, PartialEq, Eq)]
59#[non_exhaustive]
60pub struct SchemaSyncReport {
61 pub tables: Vec<String>,
63 pub changes: Vec<SchemaSyncChange>,
65}
66
67#[derive(Debug, Clone, PartialEq, Eq)]
69#[non_exhaustive]
70pub struct SchemaDataViolation {
71 pub table: String,
73 pub object: String,
75 pub primary_keys: Vec<String>,
77}
78
79#[derive(Debug, Clone, Default, PartialEq, Eq)]
81#[non_exhaustive]
82pub struct SchemaPreflightReport {
83 pub plan: SchemaSyncReport,
85 pub violations: Vec<SchemaDataViolation>,
87}
88
89impl SchemaPreflightReport {
90 pub fn is_safe(&self) -> bool {
92 self.violations.is_empty()
93 }
94}
95
96impl SchemaSyncReport {
97 pub fn is_noop(&self) -> bool {
99 self.changes.is_empty()
100 }
101}