From 802519949967f65813b43d6da28350e8c05d571f Mon Sep 17 00:00:00 2001 From: Ryan Kopf Date: Wed, 28 Feb 2024 14:03:05 -0600 Subject: [PATCH] Fix the handling of new mod files. (#2064) Co-authored-by: ryankopf --- sea-orm-cli/src/commands/migrate.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sea-orm-cli/src/commands/migrate.rs b/sea-orm-cli/src/commands/migrate.rs index 5c86364b..ce16ebb8 100644 --- a/sea-orm-cli/src/commands/migrate.rs +++ b/sea-orm-cli/src/commands/migrate.rs @@ -226,7 +226,11 @@ fn update_migrator(migration_name: &str, migration_dir: &str) -> Result<(), Box< // find existing mod declarations, add new line let mod_regex = Regex::new(r"mod\s+(?Pm\d{8}_\d{6}_\w+);")?; let mods: Vec<_> = mod_regex.captures_iter(&migrator_content).collect(); - let mods_end = mods.last().unwrap().get(0).unwrap().end() + 1; + let mods_end = if let Some(last_match) = mods.last() { + last_match.get(0).unwrap().end() + 1 + } else { + migrator_content.len() + }; updated_migrator_content.insert_str(mods_end, format!("mod {migration_name};\n").as_str()); // build new vector from declared migration modules