From 85d53a3358819d15788e1196d110fb6fd7199c67 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 30 Jun 2021 17:06:02 -0600 Subject: delete gather_migrations since it gets miscached --- src/cli/make_migrations.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/cli') 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 = 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 } } -- cgit v1.2.3