Skip to content

Commit 49e310f

Browse files
authored
Merge pull request diesel-rs#1205 from diesel-rs/sg-rm-migration-sorting-behavior
Remove special cased ordering in `migration list`
2 parents 67ab591 + f264dbf commit 49e310f

2 files changed

Lines changed: 6 additions & 29 deletions

File tree

diesel_cli/src/main.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ fn run_migration_command(matches: &ArgMatches) {
7676
call_with_conn!(database_url, redo_latest_migration(&dir));
7777
}
7878
("list", Some(args)) => {
79-
use std::cmp::Ordering;
8079
use std::ffi::OsStr;
8180

8281
let database_url = database::database_url(matches);
@@ -100,29 +99,7 @@ fn run_migration_command(matches: &ArgMatches) {
10099
})
101100
.collect::<Vec<_>>();
102101

103-
// sort migrations by version timestamp, push non-conforming timestamped versions to the bottom
104-
sorted.sort_by(|a, b| {
105-
let version_a = a.0
106-
.split('_')
107-
.nth(0)
108-
.expect(&format!("Unexpected version format {:?}", a.0));
109-
let ver_date_a = Utc.datetime_from_str(version_a, TIMESTAMP_FORMAT);
110-
let version_b = b.0
111-
.split('_')
112-
.nth(0)
113-
.expect(&format!("Unexpected version format {:?}", b.0));
114-
let ver_date_b = Utc.datetime_from_str(version_b, TIMESTAMP_FORMAT);
115-
match (ver_date_a.is_ok(), ver_date_b.is_ok()) {
116-
(false, false) => version_a.to_lowercase().cmp(&version_b.to_lowercase()),
117-
(true, false) => Ordering::Less,
118-
(false, true) => Ordering::Greater,
119-
(true, true) => {
120-
let a = ver_date_a.unwrap();
121-
let b = ver_date_b.unwrap();
122-
a.cmp(&b)
123-
}
124-
}
125-
});
102+
sorted.sort();
126103

127104
println!("Migrations:");
128105
for (name, applied) in sorted {

diesel_cli/tests/migration_list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn migration_list_orders_unknown_timestamps_last() {
117117
}
118118

119119
#[test]
120-
fn migration_list_orders_nontimestamp_versions_lexicographically() {
120+
fn migration_list_orders_nontimestamp_versions_alphabetically() {
121121
let p = project("migration_list_nontimestamp_versions")
122122
.folder("migrations")
123123
.build();
@@ -133,14 +133,14 @@ fn migration_list_orders_nontimestamp_versions_lexicographically() {
133133
let tag5 = "aa_migration";
134134
p.create_migration(&tag5, "", "");
135135

136-
let tag2 = "!wow_migration";
137-
p.create_migration(&tag2, "", "");
136+
let tag1 = "!wow_migration";
137+
p.create_migration(&tag1, "", "");
138138

139139
let tag3 = "7letters";
140140
p.create_migration(&tag3, "", "");
141141

142-
let tag1 = format!("{}_stamped_migration", Utc::now().format(TIMESTAMP_FORMAT));
143-
p.create_migration(&tag1, "", "");
142+
let tag2 = format!("{}_stamped_migration", Utc::now().format(TIMESTAMP_FORMAT));
143+
p.create_migration(&tag2, "", "");
144144

145145
let result = p.command("migration").arg("list").run();
146146
assert!(result.is_success(), "Result was unsuccessful {:?}", result);

0 commit comments

Comments
 (0)