schema-sync 1.0.0

Production-grade schema synchronization for multi-tenant databases
Documentation
//! 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(())
//! }
//! ```

pub mod adapters;
pub mod diff;
pub mod engine;
pub mod errors;
pub mod planner;
pub mod executor;
pub mod snapshot;
pub mod cli;

/// Re-exports for convenience
pub mod prelude {
    pub use crate::adapters::{DatabaseAdapter, MigrationRunner, SchemaInspector};
    pub use crate::diff::SchemaDiff;
    pub use crate::engine::Engine;
    pub use crate::errors::{Error, Result};
    pub use crate::planner::Planner;
    pub use crate::executor::Executor;
    pub use crate::snapshot::{SchemaSnapshot, SnapshotStore};
    pub use crate::cli::TenantContext;
}