tenebrous-dicebot/src/db/data_migrations.rs

29 lines
1022 B
Rust
Raw Normal View History

use crate::db::errors::{DataError, MigrationError};
2020-10-30 21:48:52 +00:00
use crate::db::variables::migrations::*;
use crate::db::Database;
use phf::phf_map;
2020-10-30 21:48:52 +00:00
pub(super) type DataMigration = (fn(&Database) -> Result<(), DataError>, &'static str);
static MIGRATIONS: phf::Map<u32, DataMigration> = phf_map! {
1u32 => (add_room_user_variable_count::migrate, "add_room_user_variable_count"),
2020-10-30 21:50:21 +00:00
2u32 => (delete_v0_schema, "delete_v0_schema"),
3u32 => (delete_variable_count, "delete_variable_count"),
4u32 => (change_delineator_delimiter::migrate, "change_delineator_delimiter"),
5u32 => (change_tree_structure::migrate, "change_tree_structure"),
};
pub fn get_migrations(versions: &[u32]) -> Result<Vec<DataMigration>, MigrationError> {
let mut migrations: Vec<DataMigration> = vec![];
for version in versions {
match MIGRATIONS.get(version) {
Some(func) => migrations.push(*func),
None => return Err(MigrationError::MigrationNotFound(*version)),
}
}
Ok(migrations)
}