Skip to content

Commit 0fe33e5

Browse files
authored
Merge pull request #107 from dev-five-git/add-id
Add
2 parents 91fb82e + e728275 commit 0fe33e5

19 files changed

Lines changed: 174 additions & 13 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"changes":{"crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch"},"note":"Add migration id","date":"2026-02-10T15:23:54.389369700Z"}

Cargo.lock

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vespertide-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ clap = { version = "4", features = ["derive"] }
1515
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }
1616
colored = "3"
1717
dialoguer = "0.12"
18+
uuid = { version = "1", features = ["v4"] }
1819
serde_json = "1"
1920
serde_yaml = "0.9"
2021
schemars = "1.2"

crates/vespertide-cli/src/commands/log.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ mod tests {
136136
fn write_migration(cfg: &VespertideConfig) {
137137
fs::create_dir_all(cfg.migrations_dir()).unwrap();
138138
let plan = MigrationPlan {
139+
id: String::new(),
139140
comment: Some("init".into()),
140141
created_at: Some("2024-01-01T00:00:00Z".into()),
141142
version: 1,
@@ -248,6 +249,7 @@ mod tests {
248249

249250
// Create a migration with ModifyColumnType for SQLite, which generates multiple SQL statements
250251
let plan = MigrationPlan {
252+
id: String::new(),
251253
comment: Some("modify column type".into()),
252254
created_at: Some("2024-01-01T00:00:00Z".into()),
253255
version: 1,

crates/vespertide-cli/src/commands/revision.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ pub async fn cmd_revision(message: String, fill_with_args: Vec<String>) -> Resul
303303
prompt_enum_value,
304304
)?;
305305

306+
plan.id = uuid::Uuid::new_v4().to_string();
306307
plan.comment = Some(message);
307308
if plan.created_at.is_none() {
308309
// Record creation time in RFC3339 (UTC).
@@ -521,6 +522,7 @@ mod tests {
521522
fn check_non_nullable_fk_add_column_fails() {
522523
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType};
523524
let plan = MigrationPlan {
525+
id: String::new(),
524526
comment: None,
525527
created_at: None,
526528
version: 2,
@@ -567,6 +569,7 @@ mod tests {
567569
fn check_nullable_fk_add_column_ok() {
568570
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType};
569571
let plan = MigrationPlan {
572+
id: String::new(),
570573
comment: None,
571574
created_at: None,
572575
version: 2,
@@ -607,6 +610,7 @@ mod tests {
607610
// Regular non-nullable column without FK should NOT be blocked
608611
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType};
609612
let plan = MigrationPlan {
613+
id: String::new(),
610614
comment: None,
611615
created_at: None,
612616
version: 2,
@@ -671,6 +675,7 @@ mod tests {
671675
use vespertide_core::MigrationPlan;
672676

673677
let mut plan = MigrationPlan {
678+
id: String::new(),
674679
comment: None,
675680
created_at: None,
676681
version: 1,
@@ -712,6 +717,7 @@ mod tests {
712717
use vespertide_core::MigrationPlan;
713718

714719
let mut plan = MigrationPlan {
720+
id: String::new(),
715721
comment: None,
716722
created_at: None,
717723
version: 1,
@@ -744,6 +750,7 @@ mod tests {
744750
use vespertide_core::MigrationPlan;
745751

746752
let mut plan = MigrationPlan {
753+
id: String::new(),
747754
comment: None,
748755
created_at: None,
749756
version: 1,
@@ -786,6 +793,7 @@ mod tests {
786793
use vespertide_core::MigrationPlan;
787794

788795
let mut plan = MigrationPlan {
796+
id: String::new(),
789797
comment: None,
790798
created_at: None,
791799
version: 1,
@@ -828,6 +836,7 @@ mod tests {
828836
use vespertide_core::MigrationPlan;
829837

830838
let mut plan = MigrationPlan {
839+
id: String::new(),
831840
comment: None,
832841
created_at: None,
833842
version: 1,
@@ -888,6 +897,7 @@ mod tests {
888897
use vespertide_core::MigrationPlan;
889898

890899
let mut plan = MigrationPlan {
900+
id: String::new(),
891901
comment: None,
892902
created_at: None,
893903
version: 1,
@@ -1149,6 +1159,7 @@ mod tests {
11491159
use vespertide_core::MigrationPlan;
11501160

11511161
let mut plan = MigrationPlan {
1162+
id: String::new(),
11521163
comment: None,
11531164
created_at: None,
11541165
version: 1,
@@ -1206,6 +1217,7 @@ mod tests {
12061217

12071218
// Plan with no missing fill_with values (nullable column)
12081219
let mut plan = MigrationPlan {
1220+
id: String::new(),
12091221
comment: None,
12101222
created_at: None,
12111223
version: 1,
@@ -1249,6 +1261,7 @@ mod tests {
12491261
use vespertide_core::MigrationPlan;
12501262

12511263
let mut plan = MigrationPlan {
1264+
id: String::new(),
12521265
comment: None,
12531266
created_at: None,
12541267
version: 1,
@@ -1299,6 +1312,7 @@ mod tests {
12991312
use vespertide_core::MigrationPlan;
13001313

13011314
let mut plan = MigrationPlan {
1315+
id: String::new(),
13021316
comment: None,
13031317
created_at: None,
13041318
version: 1,

crates/vespertide-cli/src/commands/sql.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ mod tests {
227227
write_model("users");
228228

229229
let plan = MigrationPlan {
230+
id: String::new(),
230231
comment: None,
231232
created_at: None,
232233
version: 1,
@@ -267,6 +268,7 @@ mod tests {
267268
write_model("users");
268269

269270
let plan = MigrationPlan {
271+
id: String::new(),
270272
comment: None,
271273
created_at: None,
272274
version: 1,
@@ -307,6 +309,7 @@ mod tests {
307309
write_model("users");
308310

309311
let plan = MigrationPlan {
312+
id: String::new(),
310313
comment: None,
311314
created_at: None,
312315
version: 1,
@@ -341,6 +344,7 @@ mod tests {
341344
#[serial]
342345
async fn emit_sql_prints_created_at_and_comment_postgres() {
343346
let plan = MigrationPlan {
347+
id: String::new(),
344348
comment: Some("with comment".into()),
345349
created_at: Some("2024-01-02T00:00:00Z".into()),
346350
version: 1,
@@ -357,6 +361,7 @@ mod tests {
357361
#[serial]
358362
async fn emit_sql_prints_created_at_and_comment_mysql() {
359363
let plan = MigrationPlan {
364+
id: String::new(),
360365
comment: Some("with comment".into()),
361366
created_at: Some("2024-01-02T00:00:00Z".into()),
362367
version: 1,
@@ -373,6 +378,7 @@ mod tests {
373378
#[serial]
374379
async fn emit_sql_prints_created_at_and_comment_sqlite() {
375380
let plan = MigrationPlan {
381+
id: String::new(),
376382
comment: Some("with comment".into()),
377383
created_at: Some("2024-01-02T00:00:00Z".into()),
378384
version: 1,
@@ -389,6 +395,7 @@ mod tests {
389395
#[serial]
390396
async fn emit_sql_multiple_queries() {
391397
let plan = MigrationPlan {
398+
id: String::new(),
392399
comment: None,
393400
created_at: None,
394401
version: 1,
@@ -434,6 +441,7 @@ mod tests {
434441

435442
// Create a migration that adds a NOT NULL column in SQLite, which generates multiple queries
436443
let plan = MigrationPlan {
444+
id: String::new(),
437445
comment: None,
438446
created_at: None,
439447
version: 1,

crates/vespertide-cli/src/commands/status.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ mod tests {
225225
fn write_migration(cfg: &VespertideConfig) {
226226
fs::create_dir_all(cfg.migrations_dir()).unwrap();
227227
let plan = MigrationPlan {
228+
id: String::new(),
228229
comment: Some("init".into()),
229230
created_at: Some("2024-01-01T00:00:00Z".into()),
230231
version: 1,

crates/vespertide-cli/src/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,14 @@ mod tests {
226226

227227
fs::create_dir_all("migrations").unwrap();
228228
let plan1 = MigrationPlan {
229+
id: String::new(),
229230
comment: Some("first".into()),
230231
created_at: None,
231232
version: 2,
232233
actions: vec![],
233234
};
234235
let plan0 = MigrationPlan {
236+
id: String::new(),
235237
comment: Some("zero".into()),
236238
created_at: None,
237239
version: 1,

crates/vespertide-core/src/action.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use std::fmt;
66
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
77
#[serde(rename_all = "snake_case")]
88
pub struct MigrationPlan {
9+
/// Unique identifier for this migration (UUID format).
10+
/// Defaults to empty string for backward compatibility with old migration files.
11+
#[serde(default)]
12+
pub id: String,
913
pub comment: Option<String>,
1014
#[serde(default)]
1115
pub created_at: Option<String>,
@@ -810,6 +814,7 @@ mod tests {
810814
#[test]
811815
fn test_migration_plan_with_prefix() {
812816
let plan = MigrationPlan {
817+
id: String::new(),
813818
comment: Some("test".into()),
814819
created_at: None,
815820
version: 1,

crates/vespertide-core/src/migration.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ pub enum MigrationError {
99
NotImplemented,
1010
#[error("database error: {0}")]
1111
DatabaseError(String),
12+
#[error(
13+
"migration id mismatch for version {version}: expected '{expected}', found '{found}' in database"
14+
)]
15+
IdMismatch {
16+
version: u32,
17+
expected: String,
18+
found: String,
19+
},
1220
}

0 commit comments

Comments
 (0)