From 6b21b0aff8bc4dc2c30d3d8b55147bc081507635 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Fri, 30 Oct 2020 21:48:52 +0000 Subject: [PATCH] Add string name to migrations --- src/db.rs | 5 +++-- src/db/data_migrations.rs | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/db.rs b/src/db.rs index 9dd0650..532153f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -46,11 +46,12 @@ impl Database { let migrations = data_migrations::get_migrations(&versions_to_run)?; //execute each closure. - for (version, migration_func) in versions_to_run.iter().zip(migrations) { + for (version, migration) in versions_to_run.iter().zip(migrations) { + let (migration_func, name) = migration; //This needs to be transactional on migrations //keyspace. abort on migration func error. - info!("Applying migration: {}", version); + info!("Applying migration {} :: {}", version, name); match migration_func(&self) { Ok(_) => Ok(()), Err(e) => Err(e), diff --git a/src/db/data_migrations.rs b/src/db/data_migrations.rs index 838c171..5f26446 100644 --- a/src/db/data_migrations.rs +++ b/src/db/data_migrations.rs @@ -1,12 +1,12 @@ use crate::db::errors::{DataError, MigrationError}; -use crate::db::variables; +use crate::db::variables::migrations::*; use crate::db::Database; use phf::phf_map; -pub(super) type DataMigration = fn(&Database) -> Result<(), DataError>; +pub(super) type DataMigration = (fn(&Database) -> Result<(), DataError>, &'static str); static MIGRATIONS: phf::Map = phf_map! { - 1u32 => variables::migrations::add_room_user_variable_count, + 1u32 => (add_room_user_variable_count, "add_room_user_variable_count"), }; pub fn get_migrations(versions: &[u32]) -> Result, MigrationError> {