| 177 | } |
| 178 | |
| 179 | fn create_new_migration(migration_name: &str, migration_dir: &str) -> Result<(), Box<dyn Error>> { |
| 180 | let migration_filepath = |
| 181 | get_full_migration_dir(migration_dir).join(format!("{}.rs", &migration_name)); |
| 182 | println!("Creating migration file `{}`", migration_filepath.display()); |
| 183 | // TODO: make OS agnostic |
| 184 | let migration_template = |
| 185 | include_str!("../../template/migration/src/m20220101_000001_create_table.rs"); |
| 186 | let mut migration_file = fs::File::create(migration_filepath)?; |
| 187 | migration_file.write_all(migration_template.as_bytes())?; |
| 188 | Ok(()) |
| 189 | } |
| 190 | |
| 191 | /// `get_migrator_filepath` looks for a file `migration_dir/src/lib.rs` |
| 192 | /// and returns that path if found. |