Skip to content

Commit ff809c8

Browse files
authored
do not log warning on nested dirs when finding migrations (#421)
1 parent 87092c9 commit ff809c8

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

refinery_core/src/util.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ pub fn find_migration_files(
8787
.filter_map(Result::ok)
8888
.map(DirEntry::into_path)
8989
// filter by migration file regex
90-
.filter(
91-
move |entry| match entry.file_name().and_then(OsStr::to_str) {
90+
.filter(move |entry| {
91+
if entry.is_dir() {
92+
return false;
93+
}
94+
95+
match entry.file_name().and_then(OsStr::to_str) {
9296
Some(file_name) if re.is_match(file_name) => true,
9397
Some(file_name) => {
9498
log::warn!(
@@ -98,8 +102,8 @@ pub fn find_migration_files(
98102
false
99103
}
100104
None => false,
101-
},
102-
);
105+
}
106+
});
103107

104108
Ok(file_paths)
105109
}
@@ -193,6 +197,28 @@ mod tests {
193197
assert_eq!(sql2.canonicalize().unwrap(), mods[1]);
194198
}
195199

200+
#[test]
201+
fn finds_sql_migrations_in_nested_directories() {
202+
let tmp_dir = TempDir::new().unwrap();
203+
let migrations_dir = tmp_dir.path().join("migrations");
204+
let nested_dir = migrations_dir.join("foo");
205+
fs::create_dir(&migrations_dir).unwrap();
206+
fs::create_dir(&nested_dir).unwrap();
207+
208+
let sql1 = nested_dir.join("V1__first.sql");
209+
let sql2 = nested_dir.join("V2__second.sql");
210+
fs::File::create(&sql1).unwrap();
211+
fs::File::create(&sql2).unwrap();
212+
213+
let mut mods: Vec<PathBuf> = find_migration_files(migrations_dir, MigrationType::All)
214+
.unwrap()
215+
.collect();
216+
mods.sort();
217+
218+
assert_eq!(sql1.canonicalize().unwrap(), mods[0]);
219+
assert_eq!(sql2.canonicalize().unwrap(), mods[1]);
220+
}
221+
196222
#[test]
197223
fn finds_unversioned_migrations() {
198224
let tmp_dir = TempDir::new().unwrap();

0 commit comments

Comments
 (0)