Skip to content

Commit ed2d528

Browse files
committed
Respect overridden migration directories in migration run
`revert` and `redo` are still not respecting them, but I will fix those as a separate PR since they require code changes on the Diesel side.
1 parent 73452b6 commit ed2d528

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
1414
* Added support for the `timestamp with time zone` type in PostgreSQL (referred
1515
to as `diesel::types::Timestamptz`)
1616

17+
### Fixed
18+
19+
* `diesel migrations run` will now respect migration directories overridden by
20+
command line argument or environment variable
21+
1722
## [0.7.2] - 2016-08-20
1823

1924
* Updated nightly version and syntex support.

diesel_cli/src/database.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@ use std::{env, fs};
1515
use std::path::Path;
1616

1717
macro_rules! call_with_conn {
18-
( $database_url:ident,
19-
$func:path
18+
(
19+
$database_url:ident,
20+
$($func:ident)::+
21+
) => {{
22+
call_with_conn!($database_url, $($func)::+ ())
23+
}};
24+
25+
(
26+
$database_url:ident,
27+
$($func:ident)::+ ($($args:expr),*)
2028
) => {{
2129
match ::database::backend(&$database_url) {
2230
#[cfg(feature = "postgres")]
2331
"postgres" => {
2432
let conn = PgConnection::establish(&$database_url).unwrap();
25-
$func(&conn)
33+
$($func)::+(&conn, $($args),*)
2634
},
2735
#[cfg(feature = "sqlite")]
2836
"sqlite" => {
2937
let conn = SqliteConnection::establish(&$database_url).unwrap();
30-
$func(&conn)
38+
$($func)::+(&conn, $($args),*)
3139
},
3240
_ => unreachable!("The backend function should ensure we never get here."),
3341
}

diesel_cli/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ fn main() {
114114

115115
fn run_migration_command(matches: &ArgMatches) {
116116
match matches.subcommand() {
117-
("run", Some(_)) => {
117+
("run", Some(args)) => {
118118
let database_url = database::database_url(matches);
119-
call_with_conn!(database_url, migrations::run_pending_migrations)
119+
let dir = migrations_dir(args);
120+
call_with_conn!(database_url, migrations::run_pending_migrations_in_directory(&dir, &mut stdout()))
120121
.unwrap_or_else(handle_error);
121122
}
122123
("revert", Some(_)) => {

0 commit comments

Comments
 (0)