diff options
Diffstat (limited to 'src/db/migration/change.rs')
-rw-r--r-- | src/db/migration/change.rs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/db/migration/change.rs b/src/db/migration/change.rs index b5d0dd5..8bb8bf6 100644 --- a/src/db/migration/change.rs +++ b/src/db/migration/change.rs @@ -7,34 +7,39 @@ pub enum DatabaseChange { CreateModel { name: &'static str, fields: &'static [Field], - options: &'static [CreateModelOption] + options: &'static [CreateModelOption], }, } impl DatabaseChange { pub fn apply<C: Connectable>(&self, app_name: &str, connection: &C::Connection) { - use barrel::{Migration, Table, types}; + use barrel::{types, Migration, Table}; match self { - DatabaseChange::CreateModel { name, fields, options } => { + DatabaseChange::CreateModel { + name, + fields, + options, + } => { let mut m = Migration::new(); - let columns: Vec<(&'static str, _)> = fields.iter().map(|field| match field { - Field::CharField { name, max_length } => { - let name = *name; - let _type = match max_length { - None => types::text(), - Some(max_length) => types::varchar(*max_length), - }; - (name, _type) - } - Field::DateTimeField { name } => { - (*name, types::text()) // TODO do smart things on non-sqlite - } - Field::IntField { name } => { - (*name, types::integer()) - } - }).collect(); + let columns: Vec<(&'static str, _)> = fields + .iter() + .map(|field| match field { + Field::CharField { name, max_length } => { + let name = *name; + let _type = match max_length { + None => types::text(), + Some(max_length) => types::varchar(*max_length), + }; + (name, _type) + } + Field::DateTimeField { name } => { + (*name, types::text()) // TODO do smart things on non-sqlite + } + Field::IntField { name } => (*name, types::integer()), + }) + .collect(); let callback = move |t: &mut Table| { for (name, _type) in &columns { |