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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//! Drizzle Migrations - DDL and migration infrastructure for drizzle-rs
//!
//! This crate provides:
//! - migration discovery (`MigrationDir`)
//! - runtime tracking config (`Tracking`)
//! - pure diff APIs (`diff`, `diff_schemas_with`)
//! - build-time migration generation (`build::run`)
//! - interrupted-migration reconciliation (`repair::plan`)
//!
//! # Recommended No-CLI Flow
//!
//! 1. In `build.rs`, keep `./drizzle` up to date:
//!
//! ```rust,no_run
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use drizzle_migrations::build::{Config, Output, run};
//! use drizzle_types::Dialect;
//!
//! let cfg = Config::new(Dialect::SQLite)
//! .file("./src/schema.rs")
//! .out("./drizzle");
//!
//! // Registers schema files as build.rs inputs.
//! cfg.watch();
//!
//! match run(&cfg)? {
//! Output::NoChanges => {}
//! Output::Generated { tag, .. } => {
//! println!("cargo:warning=generated migration {tag}");
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! 2. In app code, embed and run migrations:
//!
//! ```rust,no_run
//! # use drizzle_migrations::{Migration, Tracking};
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # struct Db;
//! # impl Db {
//! # fn migrate(&self, _migrations: &[Migration], _config: Tracking) -> Result<(), Box<dyn std::error::Error>> {
//! # Ok(())
//! # }
//! # }
//! # let db = Db;
//! // Usually produced by: `drizzle::include_migrations!("./drizzle")`
//! let migrations: Vec<Migration> = Vec::new();
//! db.migrate(&migrations, Tracking::SQLITE)?;
//! # Ok(())
//! # }
//! ```
//!
//! # Runtime Generation APIs (No CLI)
//!
//! Use these when you need runtime diffing between two inputs.
//!
//! ## Snapshot-to-snapshot
//!
//! ```rust
//! use drizzle_migrations::{Snapshot, diff};
//!
//! let prev = Snapshot::empty(drizzle_types::Dialect::SQLite);
//! let current = Snapshot::empty(drizzle_types::Dialect::SQLite);
//! let migration = diff(&prev, ¤t).unwrap();
//! assert!(migration.statements.is_empty());
//! ```
//!
//! ## Schema-to-schema with rename hints
//!
//! ```rust,no_run
//! use drizzle_migrations::{DiffOptions, Schema, Snapshot, diff_schemas_with};
//! use drizzle_types::Dialect;
//!
//! # #[derive(Default)]
//! # struct AppSchemaV1;
//! # #[derive(Default)]
//! # struct AppSchemaV2;
//! # impl Schema for AppSchemaV1 {
//! # fn to_snapshot(&self) -> Snapshot { Snapshot::empty(Dialect::SQLite) }
//! # fn dialect(&self) -> Dialect { Dialect::SQLite }
//! # }
//! # impl Schema for AppSchemaV2 {
//! # fn to_snapshot(&self) -> Snapshot { Snapshot::empty(Dialect::SQLite) }
//! # fn dialect(&self) -> Dialect { Dialect::SQLite }
//! # }
//! let migration = diff_schemas_with(
//! &AppSchemaV1,
//! &AppSchemaV2,
//! &DiffOptions::new()
//! .rename_table("users_old", "users")
//! .rename_column("users", "full_name", "name")
//! .strict_renames(true),
//! )?;
//! # let _ = migration;
//! # Ok::<(), drizzle_migrations::MigrationError>(())
//! ```
//!
//! # CLI Usage
//!
//! For generating migrations, use the `drizzle-cli` crate:
//!
//! ```bash
//! # Install
//! cargo install drizzle-cli
//!
//! # Initialize config
//! drizzle init --dialect sqlite
//!
//! # Generate migrations
//! drizzle generate
//!
//! # Run migrations
//! drizzle migrate
//! ```
// Core migration types
pub use Tracking;
pub use MigrationDir;
pub use ;
pub use ;
pub use ;
pub use ;
// Version constants
pub use ;
// Upgrade utilities
pub use ;
// Core traits and dialect markers
pub use ;
// Shared entity-collection backbone (per-dialect lookup helpers attach
// in `sqlite::collection` and `postgres::collection`).
pub use EntityCollection;
// Re-export serde_json for generated code
pub use serde_json;
// Schema types
pub use ;
// Programmatic migration generation
pub use ;
// Build-time generation helpers (no CLI)
pub use ;