From 42d14c943eb31753489b39ef58803c543c023bee Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 28 Jun 2021 17:12:33 -0600 Subject: fmt --- src/cli/make_migrations.rs | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'src/cli/make_migrations.rs') diff --git a/src/cli/make_migrations.rs b/src/cli/make_migrations.rs index 83e760c..b0cd341 100644 --- a/src/cli/make_migrations.rs +++ b/src/cli/make_migrations.rs @@ -5,14 +5,13 @@ use std::path::PathBuf; use quote::{quote, ToTokens}; use structopt::StructOpt; -use crate::{Settings, UrlMap, db::backend::Connectable}; -use crate::db::migration::{Migration, DatabaseChange, CreateModelOption}; +use crate::db::migration::{CreateModelOption, DatabaseChange, Migration}; use crate::db::models::{Field, ModelMeta}; +use crate::{db::backend::Connectable, Settings, UrlMap}; #[derive(StructOpt)] /// Generate migrations -pub struct MakeMigrations { -} +pub struct MakeMigrations {} #[derive(Debug)] struct AppTablesState { @@ -35,7 +34,7 @@ impl AppTablesState { Field::CharField { name, max_length: None } => quote! { Field::CharField { name: #name, max_length: None } }, Field::DateTimeField { name } => quote! { Field::DateTimeField { name: #name } }, - + Field::IntField { name } => quote! { Field::IntField { name: #name } }, } }).collect::>(); @@ -58,7 +57,12 @@ impl From<&[ModelMeta]> for AppTablesState { fn from(models: &[ModelMeta]) -> Self { let mut db = HashMap::new(); for model in models { - db.insert(model.name, TableState { fields: model.fields.into() }); + db.insert( + model.name, + TableState { + fields: model.fields.into(), + }, + ); } Self { db } } @@ -70,7 +74,11 @@ impl From<&[Migration]> for AppTablesState { for migration in migrations { for change in migration.changes { match change { - DatabaseChange::CreateModel { name, fields, options } => { + DatabaseChange::CreateModel { + name, + fields, + options, + } => { if db.contains_key(name) { if options.contains(&CreateModelOption::IfNotExist) { continue; @@ -78,7 +86,12 @@ impl From<&[Migration]> for AppTablesState { panic!("double-created table {}", name); } } - db.insert(*name, TableState { fields: (*fields).into() }); + db.insert( + *name, + TableState { + fields: (*fields).into(), + }, + ); } } } @@ -92,10 +105,17 @@ impl MakeMigrations { for app in settings.installed_apps { let expected_table_state = AppTablesState::from(app.models); let actual_table_state = AppTablesState::from(app.migrations); - let next_id = app.migrations.iter().map(|m| m.id).max().map_or(1, |x| x + 1); + let next_id = app + .migrations + .iter() + .map(|m| m.id) + .max() + .map_or(1, |x| x + 1); let name = "auto"; // TODO names let changes = actual_table_state.changes_to(expected_table_state); - if changes.is_empty() { continue; } + if changes.is_empty() { + continue; + } let migration = quote! { Migration { id: #next_id, @@ -111,9 +131,7 @@ impl MakeMigrations { }; let file_name = format!("m_{:04}_{}.rs", next_id, name); let file_text = file.into_token_stream().to_string(); - let app_folder = app.name.split("::") - .skip(1) - .collect::(); + let app_folder = app.name.split("::").skip(1).collect::(); // TODO don't explode if running in a weird place let file_path = PathBuf::from("src") .join(app_folder) -- cgit v1.2.3