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/db/migration/mod.rs | |
parent | 685b47247aad71468f190c42929ca6f0dce843fa (diff) | |
download | tosin-58d2f63f4577bc701b6bd655064cefebb65118b4.tar.gz tosin-58d2f63f4577bc701b6bd655064cefebb65118b4.zip |
actually run migrations
Diffstat (limited to 'src/db/migration/mod.rs')
-rw-r--r-- | src/db/migration/mod.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/db/migration/mod.rs b/src/db/migration/mod.rs index d53f46b..d511f88 100644 --- a/src/db/migration/mod.rs +++ b/src/db/migration/mod.rs @@ -1,5 +1,13 @@ pub use tosin_macros::gather_migrations as gather; +use diesel::{Connection, result::Error as DieselError}; + +use crate::db::backend::Connectable; + +mod change; + +pub use change::*; + pub struct Migration { pub id: usize, pub name: &'static str, @@ -7,6 +15,15 @@ pub struct Migration { pub changes: &'static [DatabaseChange], } -pub enum DatabaseChange { - CreateModel, +impl Migration { + pub fn apply<C: Connectable>(&self, app_name: &str, connection: &C::Connection) { + // TODO prevent double-applying + connection.transaction::<_, DieselError, _>(|| { + for change in self.changes { + change.apply::<C>(app_name, connection); + } + + Ok(()) + }).unwrap(); + } } |