Skip to content

Commit ce1a4a6

Browse files
committed
Cleanup func
1 parent 9897817 commit ce1a4a6

1 file changed

Lines changed: 17 additions & 42 deletions

File tree

  • crates/vespertide-macro/src

crates/vespertide-macro/src/lib.rs

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,9 @@ impl Parse for MacroInput {
5454
}
5555
}
5656

57-
/// Build a migration block (non-verbose).
5857
pub(crate) fn build_migration_block(
5958
migration: &vespertide_core::MigrationPlan,
6059
baseline_schema: &mut Vec<vespertide_core::TableDef>,
61-
) -> Result<proc_macro2::TokenStream, String> {
62-
build_migration_block_inner(migration, baseline_schema, false)
63-
}
64-
65-
/// Build a migration block with optional verbose logging.
66-
pub(crate) fn build_migration_block_verbose(
67-
migration: &vespertide_core::MigrationPlan,
68-
baseline_schema: &mut Vec<vespertide_core::TableDef>,
69-
verbose: bool,
70-
) -> Result<proc_macro2::TokenStream, String> {
71-
build_migration_block_inner(migration, baseline_schema, verbose)
72-
}
73-
74-
fn build_migration_block_inner(
75-
migration: &vespertide_core::MigrationPlan,
76-
baseline_schema: &mut Vec<vespertide_core::TableDef>,
7760
verbose: bool,
7861
) -> Result<proc_macro2::TokenStream, String> {
7962
let version = migration.version;
@@ -229,14 +212,6 @@ fn generate_migration_code(
229212
pool: &Expr,
230213
version_table: &str,
231214
migration_blocks: Vec<proc_macro2::TokenStream>,
232-
) -> proc_macro2::TokenStream {
233-
generate_migration_code_inner(pool, version_table, migration_blocks, false)
234-
}
235-
236-
fn generate_migration_code_inner(
237-
pool: &Expr,
238-
version_table: &str,
239-
migration_blocks: Vec<proc_macro2::TokenStream>,
240215
verbose: bool,
241216
) -> proc_macro2::TokenStream {
242217
let verbose_current_version = if verbose {
@@ -366,15 +341,15 @@ pub(crate) fn vespertide_migration_impl(
366341
for migration in &migrations {
367342
// Apply prefix to migration table names
368343
let prefixed_migration = migration.clone().with_prefix(prefix);
369-
match build_migration_block_verbose(&prefixed_migration, &mut baseline_schema, verbose) {
344+
match build_migration_block(&prefixed_migration, &mut baseline_schema, verbose) {
370345
Ok(block) => migration_blocks.push(block),
371346
Err(e) => {
372347
return syn::Error::new(proc_macro2::Span::call_site(), e).to_compile_error();
373348
}
374349
}
375350
}
376351

377-
generate_migration_code_inner(pool, &version_table, migration_blocks, verbose)
352+
generate_migration_code(pool, &version_table, migration_blocks, verbose)
378353
}
379354

380355
/// Zero-runtime migration entry point.
@@ -511,7 +486,7 @@ mod tests {
511486
};
512487

513488
let mut baseline = Vec::new();
514-
let result = build_migration_block(&migration, &mut baseline);
489+
let result = build_migration_block(&migration, &mut baseline, false);
515490

516491
assert!(result.is_ok());
517492
let block = result.unwrap();
@@ -541,7 +516,7 @@ mod tests {
541516
};
542517

543518
let mut baseline = Vec::new();
544-
let _ = build_migration_block(&create_migration, &mut baseline);
519+
let _ = build_migration_block(&create_migration, &mut baseline, false);
545520

546521
// Now add a column
547522
let add_column_migration = MigrationPlan {
@@ -565,7 +540,7 @@ mod tests {
565540
}],
566541
};
567542

568-
let result = build_migration_block(&add_column_migration, &mut baseline);
543+
let result = build_migration_block(&add_column_migration, &mut baseline, false);
569544
assert!(result.is_ok());
570545
let block = result.unwrap();
571546
let block_str = block.to_string();
@@ -596,7 +571,7 @@ mod tests {
596571
};
597572

598573
let mut baseline = Vec::new();
599-
let result = build_migration_block(&migration, &mut baseline);
574+
let result = build_migration_block(&migration, &mut baseline, false);
600575

601576
assert!(result.is_ok());
602577
assert_eq!(baseline.len(), 2);
@@ -620,9 +595,9 @@ mod tests {
620595
};
621596

622597
let mut baseline = Vec::new();
623-
let block = build_migration_block(&migration, &mut baseline).unwrap();
598+
let block = build_migration_block(&migration, &mut baseline, false).unwrap();
624599

625-
let generated = generate_migration_code(&pool, version_table, vec![block]);
600+
let generated = generate_migration_code(&pool, version_table, vec![block], false);
626601
let generated_str = generated.to_string();
627602

628603
// Verify the generated code structure
@@ -638,7 +613,7 @@ mod tests {
638613
let pool: Expr = syn::parse_str("pool").unwrap();
639614
let version_table = "vespertide_version";
640615

641-
let generated = generate_migration_code(&pool, version_table, vec![]);
616+
let generated = generate_migration_code(&pool, version_table, vec![], false);
642617
let generated_str = generated.to_string();
643618

644619
// Should still generate the wrapper code
@@ -662,7 +637,7 @@ mod tests {
662637
constraints: vec![],
663638
}],
664639
};
665-
let block1 = build_migration_block(&migration1, &mut baseline).unwrap();
640+
let block1 = build_migration_block(&migration1, &mut baseline, false).unwrap();
666641

667642
let migration2 = MigrationPlan {
668643
version: 2,
@@ -674,9 +649,9 @@ mod tests {
674649
constraints: vec![],
675650
}],
676651
};
677-
let block2 = build_migration_block(&migration2, &mut baseline).unwrap();
652+
let block2 = build_migration_block(&migration2, &mut baseline, false).unwrap();
678653

679-
let generated = generate_migration_code(&pool, "migrations", vec![block1, block2]);
654+
let generated = generate_migration_code(&pool, "migrations", vec![block1, block2], false);
680655
let generated_str = generated.to_string();
681656

682657
// Both version checks should be present
@@ -698,7 +673,7 @@ mod tests {
698673
};
699674

700675
let mut baseline = Vec::new();
701-
let result = build_migration_block(&migration, &mut baseline);
676+
let result = build_migration_block(&migration, &mut baseline, false);
702677
assert!(result.is_ok());
703678

704679
let block_str = result.unwrap().to_string();
@@ -724,7 +699,7 @@ mod tests {
724699
};
725700

726701
let mut baseline = Vec::new();
727-
let _ = build_migration_block(&create_migration, &mut baseline);
702+
let _ = build_migration_block(&create_migration, &mut baseline, false);
728703
assert_eq!(baseline.len(), 1);
729704

730705
// Now delete it
@@ -737,7 +712,7 @@ mod tests {
737712
}],
738713
};
739714

740-
let result = build_migration_block(&delete_migration, &mut baseline);
715+
let result = build_migration_block(&delete_migration, &mut baseline, false);
741716
assert!(result.is_ok());
742717
let block_str = result.unwrap().to_string();
743718
assert!(block_str.contains("DROP TABLE"));
@@ -773,7 +748,7 @@ mod tests {
773748
};
774749

775750
let mut baseline = Vec::new();
776-
let result = build_migration_block(&migration, &mut baseline);
751+
let result = build_migration_block(&migration, &mut baseline, false);
777752
assert!(result.is_ok());
778753

779754
// Table should be normalized with index
@@ -797,7 +772,7 @@ mod tests {
797772
};
798773

799774
let mut baseline = Vec::new();
800-
let result = build_migration_block(&migration, &mut baseline);
775+
let result = build_migration_block(&migration, &mut baseline, false);
801776

802777
assert!(result.is_err());
803778
let err = result.unwrap_err();

0 commit comments

Comments
 (0)