File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use toml;
99use super :: { find_project_root, handle_error} ;
1010use print_schema;
1111
12- #[ derive( Deserialize ) ]
12+ #[ derive( Deserialize , Default ) ]
1313#[ serde( deny_unknown_fields) ]
1414pub struct Config {
1515 #[ serde( default ) ]
@@ -31,9 +31,14 @@ impl Config {
3131
3232 pub fn read ( matches : & ArgMatches ) -> Result < Self , Box < Error > > {
3333 let path = Self :: file_path ( matches) ;
34- let mut bytes = Vec :: new ( ) ;
35- fs:: File :: open ( path) ?. read_to_end ( & mut bytes) ?;
36- toml:: from_slice ( & bytes) . map_err ( Into :: into)
34+
35+ if path. exists ( ) {
36+ let mut bytes = Vec :: new ( ) ;
37+ fs:: File :: open ( path) ?. read_to_end ( & mut bytes) ?;
38+ toml:: from_slice ( & bytes) . map_err ( Into :: into)
39+ } else {
40+ Ok ( Self :: default ( ) )
41+ }
3742 }
3843}
3944
Original file line number Diff line number Diff line change @@ -346,3 +346,31 @@ file = "src/my_schema.rs"
346346 ) ;
347347 assert ! ( p. has_file( "src/my_schema.rs" ) ) ;
348348}
349+
350+ #[ test]
351+ fn migrations_can_be_run_with_no_config_file ( ) {
352+ let p = project ( "migration_run_no_config_file" )
353+ . folder ( "migrations" )
354+ . build ( ) ;
355+ let db = database ( & p. database_url ( ) ) ;
356+
357+ p. command ( "database" ) . arg ( "setup" ) . run ( ) ;
358+
359+ p. create_migration (
360+ "12345_create_users_table" ,
361+ "CREATE TABLE users ( id INTEGER )" ,
362+ "DROP TABLE users" ,
363+ ) ;
364+
365+ assert ! ( !db. table_exists( "users" ) ) ;
366+
367+ let result = p. command ( "migration" ) . arg ( "run" ) . run ( ) ;
368+
369+ assert ! ( result. is_success( ) , "Result was unsuccessful {:?}" , result) ;
370+ assert ! (
371+ result. stdout( ) . contains( "Running migration 12345" ) ,
372+ "Unexpected stdout {}" ,
373+ result. stdout( )
374+ ) ;
375+ assert ! ( db. table_exists( "users" ) ) ;
376+ }
You can’t perform that action at this time.
0 commit comments