From 40ae61424dfeb036c2382348ebd4d859c80cd766 Mon Sep 17 00:00:00 2001 From: ryankopf Date: Sun, 14 Jan 2024 15:38:27 -0600 Subject: [PATCH] Fix the handling of new mod files. --- 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 5c86364b27..ce16ebb8bc 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