aboutsummaryrefslogtreecommitdiff
path: root/src/cli
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-06-30 17:06:02 -0600
committerMelody Horn <melody@boringcactus.com>2021-06-30 17:06:02 -0600
commit85d53a3358819d15788e1196d110fb6fd7199c67 (patch)
tree6d8a8ea21ed967c13fafa5fa90e133e6e75f8f84 /src/cli
parentbc874c9d1363d3bf8865ea7a629eb976e23386b3 (diff)
downloadtosin-85d53a3358819d15788e1196d110fb6fd7199c67.tar.gz
tosin-85d53a3358819d15788e1196d110fb6fd7199c67.zip
delete gather_migrations since it gets miscached
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/make_migrations.rs32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/cli/make_migrations.rs b/src/cli/make_migrations.rs
index d4ddcbf..98aebeb 100644
--- a/src/cli/make_migrations.rs
+++ b/src/cli/make_migrations.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use std::fs;
-use std::path::{Path, PathBuf};
+use std::path::Path;
use quote::{quote, ToTokens};
use structopt::StructOpt;
@@ -125,7 +125,8 @@ impl MakeMigrations {
}
};
let file = quote! {
- use tosin::db::migration::Migration;
+ use tosin::db::migration::{DatabaseChange, Migration};
+ use tosin::db::models::Field;
pub const MIGRATION: Migration = #migration;
};
@@ -135,9 +136,34 @@ impl MakeMigrations {
let app_folder = app_mod_rs
.parent()
.expect("app mod.rs lives at filesystem root???");
- let file_path = app_folder.join("migrations").join(file_name);
+ let migrations_dir = app_folder.join("migrations");
+ let file_path = migrations_dir.join(file_name);
println!("Saving migration to {}...", file_path.display());
fs::write(file_path, file_text).unwrap();
+
+ // update mod.rs bc the fancy gather!() shit doesn't actually invalidate partial compilation
+ let migrations: Vec<syn::Ident> = migrations_dir
+ .read_dir()
+ .unwrap()
+ .map(Result::unwrap)
+ .map(|x| x.path().file_stem().unwrap().to_string_lossy().into_owned())
+ .filter(|x| x != "mod")
+ .map(|x| syn::parse_str(&x).unwrap())
+ .collect();
+
+ let mod_file = quote! {
+ use tosin::db::migration::Migration;
+
+ #( mod #migrations; )*
+
+ pub const ALL: &[Migration] = &[
+ #(#migrations::MIGRATION),*
+ ];
+ };
+ let mod_file_path = migrations_dir.join("mod.rs");
+ let mod_file_text = mod_file.into_token_stream().to_string();
+ fs::write(mod_file_path, mod_file_text).unwrap();
+
// TODO cargo fmt
}
}