Add string name to migrations

This commit is contained in:
projectmoon 2020-10-30 21:48:52 +00:00 committed by ProjectMoon
parent 3cec676b2f
commit 6b21b0aff8
2 changed files with 6 additions and 5 deletions

View File

@ -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),

View File

@ -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<u32, DataMigration> = 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<Vec<DataMigration>, MigrationError> {