@@ -391,7 +391,14 @@ pub async fn cmd_revision(message: String, fill_with_args: Vec<String>) -> Resul
391391 ) ?;
392392
393393 // Handle any missing enum fill_with values (for removed enum values) interactively
394- handle_missing_enum_fill_with ( & mut plan, & baseline_schema, prompt_enum_value) ?;
394+ handle_missing_enum_fill_with ( & mut plan, & baseline_schema, |prompt, values| {
395+ let selected = prompt_enum_value ( prompt, values) ?;
396+ // Strip SQL quotes — BTreeMap stores bare enum names, SQL layer handles quoting
397+ Ok ( selected
398+ . trim_start_matches ( '\'' )
399+ . trim_end_matches ( '\'' )
400+ . to_string ( ) )
401+ } ) ?;
395402
396403 plan. id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
397404 plan. comment = Some ( message) ;
@@ -1554,7 +1561,7 @@ mod tests {
15541561
15551562 // Mock prompt: always select first remaining value
15561563 let mock_enum =
1557- |_prompt : & str , values : & [ String ] | -> Result < String > { Ok ( format ! ( "'{}'" , values[ 0 ] ) ) } ;
1564+ |_prompt : & str , values : & [ String ] | -> Result < String > { Ok ( values[ 0 ] . to_string ( ) ) } ;
15581565
15591566 let result = collect_enum_fill_with_values ( & missing, mock_enum) ;
15601567 assert ! ( result. is_ok( ) ) ;
@@ -1563,7 +1570,7 @@ mod tests {
15631570 assert_eq ! ( collected[ 0 ] . 0 , 0 ) ; // action_index
15641571 assert_eq ! (
15651572 collected[ 0 ] . 1 . get( "cancelled" ) ,
1566- Some ( & "' pending' " . to_string( ) )
1573+ Some ( & "pending" . to_string( ) )
15671574 ) ;
15681575 }
15691576
@@ -1581,17 +1588,17 @@ mod tests {
15811588
15821589 // Mock prompt: always select second remaining value
15831590 let mock_enum =
1584- |_prompt : & str , values : & [ String ] | -> Result < String > { Ok ( format ! ( "'{}'" , values[ 1 ] ) ) } ;
1591+ |_prompt : & str , values : & [ String ] | -> Result < String > { Ok ( values[ 1 ] . to_string ( ) ) } ;
15851592
15861593 let result = collect_enum_fill_with_values ( & missing, mock_enum) ;
15871594 assert ! ( result. is_ok( ) ) ;
15881595 let collected = result. unwrap ( ) ;
15891596 assert_eq ! ( collected[ 0 ] . 1 . len( ) , 2 ) ;
15901597 assert_eq ! (
15911598 collected[ 0 ] . 1 . get( "cancelled" ) ,
1592- Some ( & "' shipped' " . to_string( ) )
1599+ Some ( & "shipped" . to_string( ) )
15931600 ) ;
1594- assert_eq ! ( collected[ 0 ] . 1 . get( "draft" ) , Some ( & "' shipped' " . to_string( ) ) ) ;
1601+ assert_eq ! ( collected[ 0 ] . 1 . get( "draft" ) , Some ( & "shipped" . to_string( ) ) ) ;
15951602 }
15961603
15971604 #[ test]
@@ -1615,14 +1622,14 @@ mod tests {
16151622 } ;
16161623
16171624 let mut mappings = BTreeMap :: new ( ) ;
1618- mappings. insert ( "cancelled" . to_string ( ) , "' pending' " . to_string ( ) ) ;
1625+ mappings. insert ( "cancelled" . to_string ( ) , "pending" . to_string ( ) ) ;
16191626 let collected = vec ! [ ( 0usize , mappings) ] ;
16201627
16211628 apply_enum_fill_with_to_plan ( & mut plan, & collected) ;
16221629
16231630 if let MigrationAction :: ModifyColumnType { fill_with, .. } = & plan. actions [ 0 ] {
16241631 let fw = fill_with. as_ref ( ) . expect ( "fill_with should be set" ) ;
1625- assert_eq ! ( fw. get( "cancelled" ) , Some ( & "' pending' " . to_string( ) ) ) ;
1632+ assert_eq ! ( fw. get( "cancelled" ) , Some ( & "pending" . to_string( ) ) ) ;
16261633 } else {
16271634 panic ! ( "Expected ModifyColumnType" ) ;
16281635 }
@@ -1674,14 +1681,14 @@ mod tests {
16741681
16751682 // Mock: always select first remaining value
16761683 let mock_enum =
1677- |_prompt : & str , values : & [ String ] | -> Result < String > { Ok ( format ! ( "'{}'" , values[ 0 ] ) ) } ;
1684+ |_prompt : & str , values : & [ String ] | -> Result < String > { Ok ( values[ 0 ] . to_string ( ) ) } ;
16781685
16791686 let result = handle_missing_enum_fill_with ( & mut plan, & baseline, mock_enum) ;
16801687 assert ! ( result. is_ok( ) ) ;
16811688
16821689 if let MigrationAction :: ModifyColumnType { fill_with, .. } = & plan. actions [ 0 ] {
16831690 let fw = fill_with. as_ref ( ) . expect ( "fill_with should be populated" ) ;
1684- assert_eq ! ( fw. get( "cancelled" ) , Some ( & "' pending' " . to_string( ) ) ) ;
1691+ assert_eq ! ( fw. get( "cancelled" ) , Some ( & "pending" . to_string( ) ) ) ;
16851692 } else {
16861693 panic ! ( "Expected ModifyColumnType" ) ;
16871694 }
@@ -1704,4 +1711,48 @@ mod tests {
17041711 let result = handle_missing_enum_fill_with ( & mut plan, & [ ] , mock_enum) ;
17051712 assert ! ( result. is_ok( ) ) ;
17061713 }
1714+
1715+ #[ test]
1716+ fn test_apply_enum_fill_with_to_plan_extends_existing ( ) {
1717+ use vespertide_core:: { ColumnType , ComplexColumnType , EnumValues } ;
1718+
1719+ // Start with a fill_with that already has one entry
1720+ let mut existing_fw = BTreeMap :: new ( ) ;
1721+ existing_fw. insert ( "draft" . to_string ( ) , "pending" . to_string ( ) ) ;
1722+
1723+ let mut plan = MigrationPlan {
1724+ id : String :: new ( ) ,
1725+ comment : None ,
1726+ created_at : None ,
1727+ version : 2 ,
1728+ actions : vec ! [ MigrationAction :: ModifyColumnType {
1729+ table: "orders" . into( ) ,
1730+ column: "status" . into( ) ,
1731+ new_type: ColumnType :: Complex ( ComplexColumnType :: Enum {
1732+ name: "order_status" . into( ) ,
1733+ values: EnumValues :: String ( vec![ "pending" . into( ) , "shipped" . into( ) ] ) ,
1734+ } ) ,
1735+ fill_with: Some ( existing_fw) ,
1736+ } ] ,
1737+ } ;
1738+
1739+ // Collect additional mappings
1740+ let mut new_mappings = BTreeMap :: new ( ) ;
1741+ new_mappings. insert ( "cancelled" . to_string ( ) , "shipped" . to_string ( ) ) ;
1742+ let collected = vec ! [ ( 0usize , new_mappings) ] ;
1743+
1744+ apply_enum_fill_with_to_plan ( & mut plan, & collected) ;
1745+
1746+ if let MigrationAction :: ModifyColumnType { fill_with, .. } = & plan. actions [ 0 ] {
1747+ let fw = fill_with. as_ref ( ) . expect ( "fill_with should be set" ) ;
1748+ // Original entry preserved
1749+ assert_eq ! ( fw. get( "draft" ) , Some ( & "pending" . to_string( ) ) ) ;
1750+ // New entry added
1751+ assert_eq ! ( fw. get( "cancelled" ) , Some ( & "shipped" . to_string( ) ) ) ;
1752+ // Total 2 entries
1753+ assert_eq ! ( fw. len( ) , 2 ) ;
1754+ } else {
1755+ panic ! ( "Expected ModifyColumnType" ) ;
1756+ }
1757+ }
17071758}
0 commit comments