1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Developer: s4gor
//! Github: https://github.com/s4gor
//!
//! # Schema Sync
//!
//! Production-grade schema synchronization for multi-tenant databases.
//!
//! ## Architecture Overview
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ CLI Layer │
//! │ (dry-run, diff, validation, audit modes) │
//! └───────────────────────┬─────────────────────────────────────┘
//! │
//! ┌───────────────────────▼─────────────────────────────────────┐
//! │ Engine Layer │
//! │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
//! │ │ Planner │→ │ Executor │→ │ Diff │→ │ Snapshot │ │
//! │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
//! └───────────────────────┬─────────────────────────────────────┘
//! │
//! ┌───────────────────────▼─────────────────────────────────────┐
//! │ Adapter Layer │
//! │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
//! │ │ Database │ │ Migration │ │ Schema │ │
//! │ │ Adapter │ │ Runner │ │ Inspector │ │
//! │ └──────────────┘ └──────────────┘ └──────────────┘ │
//! └───────────────────────┬─────────────────────────────────────┘
//! │
//! ┌───────────────────────▼─────────────────────────────────────┐
//! │ Database-Specific Implementations │
//! │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
//! │ │PostgreSQL│ │ MySQL │ │ SQLite │ │
//! │ └──────────┘ └──────────┘ └──────────┘ │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Design Principles
//!
//! 1. **Trait-Based Extensibility**: All database operations go through traits,
//! allowing new database types to be added without changing core logic.
//!
//! 2. **Separation of Concerns**:
//! - **Adapters**: Database-specific connection and query execution
//! - **Inspectors**: Schema introspection (read-only)
//! - **Runners**: Migration execution (write operations)
//! - **Planner**: Determines what changes need to be made
//! - **Executor**: Orchestrates the execution of planned changes
//!
//! 3. **Tenant Isolation**: Every operation is scoped to a tenant context,
//! preventing cross-tenant data leakage.
//!
//! 4. **Mode-Agnostic Core**: The engine doesn't know about CLI modes;
//! modes are implemented at the CLI layer using the same engine primitives.
//!
//! ## Example Usage
//!
//! ```rust,no_run
//! use schema_sync::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! // Create adapter (PostgreSQL implementation)
//! // let adapter = PostgresAdapter::new("postgresql://...").await?;
//!
//! // Create inspector to read schema
//! // let inspector = adapter.inspector();
//!
//! // Create migration runner
//! // let runner = adapter.migration_runner();
//!
//! // Create planner, executor, and diff calculator
//! // let planner = DefaultPlanner::new();
//! // let executor = DefaultExecutor::new();
//! // let diff_calculator = DefaultDiffCalculator::new();
//!
//! // Create engine
//! // let engine = Engine::from_adapter(
//! // Box::new(adapter),
//! // Box::new(planner),
//! // Box::new(executor),
//! // Box::new(diff_calculator),
//! // None,
//! // );
//!
//! // Sync schema for a tenant
//! let tenant = TenantContext::new("tenant_123");
//! // let target_snapshot = /* get target snapshot */;
//! // let result = engine.sync_tenant(&tenant, Some(&target_snapshot), true).await?;
//!
//! // println!("Synced {} changes", result.changes_applied);
//! Ok(())
//! }
//! ```
/// Re-exports for convenience