Skip to content

Commit

Permalink
Added a .gitignore file for migration folder (#1334)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
sanihaq and billy1624 authored Mar 23, 2023
1 parent 619f20d commit 3a5707b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions sea-orm-cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(())
Expand Down
1 change: 1 addition & 0 deletions sea-orm-cli/template/migration/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target

0 comments on commit 3a5707b

Please sign in to comment.