@@ -30,18 +30,8 @@ pub fn load_migrations(config: &VespertideConfig) -> Result<Vec<MigrationPlan>>
3030 serde_json:: from_str ( & content)
3131 . with_context ( || format ! ( "parse migration: {}" , path. display( ) ) ) ?
3232 } else {
33- #[ cfg( feature = "yaml" ) ]
34- {
35- serde_yaml:: from_str ( & content)
36- . with_context ( || format ! ( "parse migration: {}" , path. display( ) ) ) ?
37- }
38- #[ cfg( not( feature = "yaml" ) ) ]
39- {
40- anyhow:: bail!(
41- "YAML support not enabled. Enable the 'yaml' feature or use JSON format: {}" ,
42- path. display( )
43- ) ;
44- }
33+ serde_yaml:: from_str ( & content)
34+ . with_context ( || format ! ( "parse migration: {}" , path. display( ) ) ) ?
4535 } ;
4636
4737 // Validate the migration plan
@@ -99,16 +89,9 @@ pub fn load_migrations_from_dir(
9989 format ! ( "Failed to parse JSON migration {}: {}" , path. display( ) , e)
10090 } ) ?
10191 } else {
102- #[ cfg( feature = "yaml" ) ]
103- {
104- serde_yaml:: from_str ( & content) . map_err ( |e| {
105- format ! ( "Failed to parse YAML migration {}: {}" , path. display( ) , e)
106- } ) ?
107- }
108- #[ cfg( not( feature = "yaml" ) ) ]
109- {
110- return Err ( format ! ( "YAML support not enabled. Enable the 'yaml' feature or use JSON format: {}" , path. display( ) ) . into ( ) ) ;
111- }
92+ serde_yaml:: from_str ( & content) . map_err ( |e| {
93+ format ! ( "Failed to parse YAML migration {}: {}" , path. display( ) , e)
94+ } ) ?
11295 } ;
11396
11497 plans. push ( plan) ;
@@ -269,7 +252,6 @@ mod tests {
269252 assert_eq ! ( plans[ 2 ] . version, 3 ) ;
270253 }
271254
272- #[ cfg( feature = "yaml" ) ]
273255 #[ test]
274256 fn test_load_migrations_from_dir_with_yaml_migration ( ) {
275257 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
@@ -297,7 +279,6 @@ actions:
297279 assert_eq ! ( plans[ 0 ] . version, 1 ) ;
298280 }
299281
300- #[ cfg( feature = "yaml" ) ]
301282 #[ test]
302283 fn test_load_migrations_from_dir_with_yml_migration ( ) {
303284 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
@@ -325,58 +306,47 @@ actions:
325306 assert_eq ! ( plans[ 0 ] . version, 1 ) ;
326307 }
327308
328- #[ test]
329- fn test_load_migrations_from_dir_with_invalid_json ( ) {
330- let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
331- let migrations_dir = temp_dir. path ( ) . join ( "migrations" ) ;
332- fs:: create_dir_all ( & migrations_dir) . unwrap ( ) ;
333-
334- let invalid_json = r#"{"version": 1, "actions": [invalid]}"# ;
335- fs:: write ( migrations_dir. join ( "0001_invalid.json" ) , invalid_json) . unwrap ( ) ;
336-
337- let result = load_migrations_from_dir ( Some ( temp_dir. path ( ) . to_path_buf ( ) ) ) ;
338- assert ! ( result. is_err( ) ) ;
339- let err_msg = result. unwrap_err ( ) . to_string ( ) ;
340- assert ! ( err_msg. contains( "Failed to parse JSON migration" ) ) ;
341- }
342-
343- #[ cfg( not( feature = "yaml" ) ) ]
344309 #[ test]
345310 #[ serial]
346- fn test_load_migrations_reports_yaml_disabled_for_runtime_loader ( ) {
311+ fn test_load_migrations_reads_yaml_for_runtime_loader ( ) {
347312 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
348313 let _guard = CwdGuard :: new ( & temp_dir. path ( ) . to_path_buf ( ) ) ;
349314 write_config ( temp_dir. path ( ) ) ;
350315 fs:: create_dir_all ( "migrations" ) . unwrap ( ) ;
351- fs:: write ( "migrations/0001_test.yaml" , "version: 1\n actions: []\n " ) . unwrap ( ) ;
352316
353- let result = load_migrations ( & VespertideConfig :: default ( ) ) ;
354- assert ! ( result. is_err( ) ) ;
355- let err_msg = result. unwrap_err ( ) . to_string ( ) ;
356- assert ! ( err_msg. contains( "YAML support not enabled" ) ) ;
357- assert ! ( err_msg. contains( "0001_test.yaml" ) ) ;
317+ let migration_content = r#"---
318+ version: 1
319+ actions:
320+ - type: create_table
321+ table: users
322+ columns:
323+ - name: id
324+ type: integer
325+ nullable: false
326+ constraints: []
327+ "# ;
328+ fs:: write ( "migrations/0001_test.yaml" , migration_content) . unwrap ( ) ;
329+
330+ let plans = load_migrations ( & VespertideConfig :: default ( ) ) . unwrap ( ) ;
331+ assert_eq ! ( plans. len( ) , 1 ) ;
332+ assert_eq ! ( plans[ 0 ] . version, 1 ) ;
358333 }
359334
360- #[ cfg( not( feature = "yaml" ) ) ]
361335 #[ test]
362- fn test_load_migrations_from_dir_reports_yaml_disabled ( ) {
336+ fn test_load_migrations_from_dir_with_invalid_json ( ) {
363337 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
364338 let migrations_dir = temp_dir. path ( ) . join ( "migrations" ) ;
365339 fs:: create_dir_all ( & migrations_dir) . unwrap ( ) ;
366- fs:: write (
367- migrations_dir. join ( "0001_test.yaml" ) ,
368- "version: 1\n actions: []\n " ,
369- )
370- . unwrap ( ) ;
340+
341+ let invalid_json = r#"{"version": 1, "actions": [invalid]}"# ;
342+ fs:: write ( migrations_dir. join ( "0001_invalid.json" ) , invalid_json) . unwrap ( ) ;
371343
372344 let result = load_migrations_from_dir ( Some ( temp_dir. path ( ) . to_path_buf ( ) ) ) ;
373345 assert ! ( result. is_err( ) ) ;
374346 let err_msg = result. unwrap_err ( ) . to_string ( ) ;
375- assert ! ( err_msg. contains( "YAML support not enabled" ) ) ;
376- assert ! ( err_msg. contains( "0001_test.yaml" ) ) ;
347+ assert ! ( err_msg. contains( "Failed to parse JSON migration" ) ) ;
377348 }
378349
379- #[ cfg( feature = "yaml" ) ]
380350 #[ test]
381351 fn test_load_migrations_from_dir_with_invalid_yaml ( ) {
382352 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
0 commit comments