MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / run_migrate_init

Function run_migrate_init

sea-orm-cli/src/commands/migrate.rs:82–127  ·  view source on GitHub ↗
(migration_dir: &str)

Source from the content-addressed store, hash-verified

80}
81
82pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box<dyn Error>> {
83 let migration_dir = match migration_dir.ends_with('/') {
84 true => migration_dir.to_string(),
85 false => format!("{migration_dir}/"),
86 };
87 println!("Initializing migration directory...");
88 macro_rules! write_file {
89 ($filename: literal) => {
90 let fn_content = |content: String| content;
91 write_file!($filename, $filename, fn_content);
92 };
93 ($filename: literal, $template: literal) => {
94 let fn_content = |content: String| content;
95 write_file!($filename, $template, fn_content);
96 };
97 ($filename: literal, $template: literal, $fn_content: expr) => {
98 let filepath = [&migration_dir, $filename].join("");
99 println!("Creating file `{}`", filepath);
100 let path = Path::new(&filepath);
101 let prefix = path.parent().unwrap();
102 fs::create_dir_all(prefix).unwrap();
103 let mut file = fs::File::create(path)?;
104 let content = include_str!(concat!("../../template/migration/", $template));
105 let content = $fn_content(content.to_string());
106 file.write_all(content.as_bytes())?;
107 };
108 }
109 write_file!("src/lib.rs");
110 write_file!("src/m20220101_000001_create_table.rs");
111 write_file!("src/main.rs");
112 write_file!("Cargo.toml", "_Cargo.toml", |content: String| {
113 let ver = format!(
114 "{}.{}.0",
115 env!("CARGO_PKG_VERSION_MAJOR"),
116 env!("CARGO_PKG_VERSION_MINOR")
117 );
118 content.replace("<sea-orm-migration-version>", &ver)
119 });
120 write_file!("README.md");
121 if glob::glob(&format!("{migration_dir}**/.git"))?.count() > 0 {
122 write_file!(".gitignore", "_gitignore");
123 }
124 println!("Done!");
125
126 Ok(())
127}
128
129pub fn run_migrate_generate(
130 migration_dir: &str,

Callers 2

run_migrate_commandFunction · 0.85
run_migrateFunction · 0.85

Calls 2

ends_withMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected