diff options
author | Melody Horn / boringcactus <melody@boringcactus.com> | 2021-06-16 14:22:50 -0600 |
---|---|---|
committer | Melody Horn / boringcactus <melody@boringcactus.com> | 2021-06-16 14:22:50 -0600 |
commit | 58d2f63f4577bc701b6bd655064cefebb65118b4 (patch) | |
tree | 0427ac03e6d0d0ed7879aecaa45cd3937939aa4e /src/cli | |
parent | 685b47247aad71468f190c42929ca6f0dce843fa (diff) | |
download | tosin-58d2f63f4577bc701b6bd655064cefebb65118b4.tar.gz tosin-58d2f63f4577bc701b6bd655064cefebb65118b4.zip |
actually run migrations
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/migrate.rs | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/cli/migrate.rs b/src/cli/migrate.rs index 4b5123a..a6efbb5 100644 --- a/src/cli/migrate.rs +++ b/src/cli/migrate.rs @@ -1,19 +1,47 @@ use structopt::StructOpt; -use crate::{Settings, UrlMap, db::backend::{Connectable, Connection}}; +use crate::{Settings, UrlMap}; +use crate::db::backend::Connectable; +use crate::db::migration::{DatabaseChange, CreateModelOption}; +use crate::db::models::Field; #[derive(StructOpt)] /// Perform database migrations pub struct Migrate { } +const CREATE_MIGRATION_TABLE: DatabaseChange = DatabaseChange::CreateModel { + name: "Migration", + fields: &[ + Field::CharField { + name: "app_name", + max_length: None, + }, + Field::IntField { + name: "migration_id", + }, + Field::CharField { + name: "migration_name", + max_length: None, + }, + Field::DateTimeField { + name: "applied_at", + } + ], + options: &[CreateModelOption::IfNotExist], +}; + impl Migrate { - pub fn execute(self, _urls: UrlMap, settings: Settings<impl Connectable>) { + pub fn execute<C: Connectable>(self, _urls: UrlMap, settings: Settings<C>) { let database = settings.database; let connection = database.connect().unwrap(); - let migration_table_vibe_check = connection.transaction::<(), diesel::result::Error, _>(|| { - todo!() - }); + CREATE_MIGRATION_TABLE.apply::<C>("tosin_meta", &connection); + + for app in settings.installed_apps { + for migration in app.migrations { + migration.apply::<C>(app.name, &connection); + } + } } } |