diff --git a/diesel_cli/src/main.rs b/diesel_cli/src/main.rs index 045248292c85..b21e99ef7014 100644 --- a/diesel_cli/src/main.rs +++ b/diesel_cli/src/main.rs @@ -183,7 +183,7 @@ fn generate_completions_command(matches: &ArgMatches) { /// Returns a `DatabaseError::ProjectRootNotFound` if no Cargo.toml is found. fn create_migrations_directory(path: &Path) -> Result { println!("Creating migrations directory at: {}", path.display()); - fs::create_dir(path)?; + fs::create_dir_all(path)?; fs::File::create(path.join(".keep"))?; Ok(path.to_owned()) } diff --git a/diesel_cli/tests/database_setup.rs b/diesel_cli/tests/database_setup.rs index ffedc1630a20..947ee706b149 100644 --- a/diesel_cli/tests/database_setup.rs +++ b/diesel_cli/tests/database_setup.rs @@ -152,6 +152,39 @@ fn database_setup_respects_migration_dir_by_arg() { assert!(db.table_exists("users")); } +#[test] +fn database_setup_respects_migration_nested_dir_by_arg() { + let p = project("database_setup_respects_migration_nested_dir_by_arg") + .folder("foo/bar") + .build(); + let db = database(&p.database_url()); + + p.create_migration_in_directory( + "foo/bar", + "12345_create_users_table", + "CREATE TABLE users ( id INTEGER )", + Some("DROP TABLE users"), + None, + ); + + // sanity check + assert!(!db.exists()); + + let result = p + .command("database") + .arg("setup") + .arg("--migration-dir=foo/bar") + .run(); + + assert!(result.is_success(), "Result was unsuccessful {:?}", result); + assert!( + result.stdout().contains("Running migration 12345"), + "Unexpected stdout {}", + result.stdout() + ); + assert!(db.table_exists("users")); +} + #[test] fn database_setup_respects_migration_dir_by_env() { let p = project("database_setup_respects_migration_dir_by_env") diff --git a/diesel_cli/tests/support/project_builder.rs b/diesel_cli/tests/support/project_builder.rs index c1199b1aba17..5110e409c599 100644 --- a/diesel_cli/tests/support/project_builder.rs +++ b/diesel_cli/tests/support/project_builder.rs @@ -45,7 +45,7 @@ impl ProjectBuilder { File::create(tempdir.path().join("Cargo.toml")).unwrap(); for folder in self.folders { - fs::create_dir(tempdir.path().join(folder)).unwrap(); + fs::create_dir_all(tempdir.path().join(folder)).unwrap(); } for (file, contents) in self.files {