diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index dd377c5a5..2b1438f78 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -45,6 +45,7 @@ tracing = { version = "0.1", default-features = false } url = { version = "2.2", default-features = false } chrono = { version = "0.4.20", default-features = false, features = ["clock"] } regex = { version = "1", default-features = false } +git2 = { version = "0.16", default-features = false } [dev-dependencies] smol = "1.2.5" diff --git a/sea-orm-cli/src/commands/migrate.rs b/sea-orm-cli/src/commands/migrate.rs index 2e5bc7b14..442c15808 100644 --- a/sea-orm-cli/src/commands/migrate.rs +++ b/sea-orm-cli/src/commands/migrate.rs @@ -89,6 +89,10 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { let fn_content = |content: String| content; write_file!($filename, $filename, fn_content); }; + ($filename: literal, $template: literal) => { + let fn_content = |content: String| content; + write_file!($filename, $template, fn_content); + }; ($filename: literal, $template: literal, $fn_content: expr) => { let filepath = [&migration_dir, $filename].join(""); println!("Creating file `{}`", filepath); @@ -113,6 +117,9 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { content.replace("", &ver) }); write_file!("README.md"); + if git2::Repository::discover(Path::new(&migration_dir)).is_ok() { + write_file!(".gitignore", "_gitignore"); + } println!("Done!"); Ok(()) diff --git a/sea-orm-cli/template/migration/_gitignore b/sea-orm-cli/template/migration/_gitignore new file mode 100644 index 000000000..c41cc9e35 --- /dev/null +++ b/sea-orm-cli/template/migration/_gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file