yang_base/database/schema_sync/
mod.rs1mod binding;
14mod dialect;
15mod driver;
16#[cfg(feature = "mysql")]
17mod inspect;
18mod model;
19#[cfg(feature = "postgres")]
20mod pg;
21mod plan;
22mod preflight;
23#[cfg(feature = "mysql")]
24mod render;
25mod sync;
26
27#[cfg(test)]
28mod __tests__;
29
30pub use binding::SchemaBindingMode;
31#[cfg(all(test, feature = "mysql"))]
32pub(super) use model::SchemaPreflightCheck;
33#[cfg(test)]
34pub(super) use model::{ExistingIndex, ExistingTableSchema};
35#[cfg(all(test, feature = "mysql"))]
36pub(super) use plan::plan_table_sync;
37#[cfg(all(test, feature = "postgres"))]
38pub(super) use plan::plan_table_sync_with;
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42#[non_exhaustive]
43pub enum SchemaSyncChangeKind {
44 CreatedTable,
46 AddedColumn,
48 RenamedColumn,
50 ModifiedColumn,
52 AddedPrimaryKey,
54 AddedIndex,
56 CreatedEnumType,
58 AddedEnumValue,
60 AddedCheck,
62 ValidatedCheck,
64 CommentedColumn,
66 AddedForeignKey,
68 ValidatedForeignKey,
70}
71
72#[derive(Debug, Clone, PartialEq, Eq)]
74#[non_exhaustive]
75pub struct SchemaSyncChange {
76 pub table: String,
78 pub object: String,
80 pub kind: SchemaSyncChangeKind,
82}
83
84#[derive(Debug, Clone, PartialEq, Eq)]
86#[non_exhaustive]
87pub struct SchemaBindingChange {
88 pub datasource: crate::datasource::DatasourceId,
90 pub table: String,
92 pub mode: SchemaBindingMode,
94 pub newly_bound: bool,
96}
97
98#[derive(Debug, Clone, Default, PartialEq, Eq)]
100#[non_exhaustive]
101pub struct SchemaSyncReport {
102 pub tables: Vec<String>,
104 pub changes: Vec<SchemaSyncChange>,
106 pub statements: Vec<String>,
108 pub deferred_statements: Vec<String>,
110 pub bindings: Vec<SchemaBindingChange>,
112}
113
114#[derive(Debug, Clone, PartialEq, Eq)]
116#[non_exhaustive]
117pub struct SchemaDataViolation {
118 pub table: String,
120 pub object: String,
122 pub primary_keys: Vec<String>,
124}
125
126#[derive(Debug, Clone, Default, PartialEq, Eq)]
128#[non_exhaustive]
129pub struct SchemaPreflightReport {
130 pub plan: SchemaSyncReport,
132 pub violations: Vec<SchemaDataViolation>,
134}
135
136impl SchemaPreflightReport {
137 pub fn is_safe(&self) -> bool {
139 self.violations.is_empty()
140 }
141}
142
143impl SchemaSyncReport {
144 pub fn is_noop(&self) -> bool {
146 self.changes.is_empty()
147 }
148}