@@ -4,7 +4,7 @@ use std::{
44 path::Path,
55};
66
7−use anyhow::{Context};
7+use anyhow::Context;
88use clap::{Args, Parser};
99use reshape::{
1010 migrations::{Action, Migration},
@@ -196,7 +196,13 @@ fn find_migrations(opts: &FindMigrationsOptions) -> anyhow::Result<Vec<Migration
196196 }
197197
198198 // Sort all files by their file names (without extension)
199− file_paths.sort_unstable_by_key(|path| path.as_path().file_stem().unwrap().to_os_string());
199+ // The files are sorted naturally, e.g. "1_test_migration" < "10_test_migration"
200+ file_paths.sort_unstable_by(|path1, path2| {
201+ let file1 = path1.as_path().file_stem().unwrap().to_str().unwrap();
202+ let file2 = path2.as_path().file_stem().unwrap().to_str().unwrap();
203+
204+ lexical_sort::natural_cmp(file1, file2)
205+ });
200206
201207 file_paths
202208 .iter()
@@ -212,8 +218,10 @@ fn find_migrations(opts: &FindMigrationsOptions) -> anyhow::Result<Vec<Migration
212218 .map(|result| {
213219 result.and_then(|(path, data)| {
214220 let extension = path.extension().and_then(|ext| ext.to_str()).unwrap();
215− let file_migration = decode_migration_file(&data, extension)
216− .with_context(|| format!("failed to parse migration file {}", path.display()))?;
221+ let file_migration =
222+ decode_migration_file(&data, extension).with_context(|| {
223+ format!("failed to parse migration file {}", path.display())
224+ })?;
217225
218226 let file_name = path.file_stem().and_then(|name| name.to_str()).unwrap();
219227 Ok(Migration {