2020-10-24 13:46:06 +00:00
|
|
|
use crate::db::errors::{DataError, MigrationError};
|
2020-10-30 21:48:52 +00:00
|
|
|
use crate::db::variables::migrations::*;
|
2020-10-24 13:46:06 +00:00
|
|
|
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);
|
2020-10-24 13:46:06 +00:00
|
|
|
|
|
|
|
static MIGRATIONS: phf::Map<u32, DataMigration> = phf_map! {
|
2020-11-01 18:59:07 +00:00
|
|
|
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"),
|
2020-10-30 22:44:19 +00:00
|
|
|
3u32 => (delete_variable_count, "delete_variable_count"),
|
2020-11-01 18:59:07 +00:00
|
|
|
4u32 => (change_delineator_delimiter::migrate, "change_delineator_delimiter")
|
2020-10-24 13:46:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|