Added a .gitignore file for migration folder (#1334)

* added .gitignore file

* add .gitignore

* only add .gitignore if not in a existing git repo

* Use `git2` to detect git repository

---------

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
This commit is contained in:
sani haq 2023-03-23 09:11:13 +05:30 committed by GitHub
parent 619f20de19
commit 3a5707b1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -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"

View File

@ -89,6 +89,10 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
content.replace("<sea-orm-migration-version>", &ver)
});
write_file!("README.md");
if git2::Repository::discover(Path::new(&migration_dir)).is_ok() {
write_file!(".gitignore", "_gitignore");
}
println!("Done!");
Ok(())

View File

@ -0,0 +1 @@
/target