Add a game system column to room info #95

Merged
projectmoon merged 1 commits from add-system into master 2022-02-02 20:56:53 +00:00
7 changed files with 385 additions and 292 deletions

616
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -33,8 +33,9 @@ futures = "0.3"
html2text = "0.2" html2text = "0.2"
phf = { version = "0.8", features = ["macros"] } phf = { version = "0.8", features = ["macros"] }
matrix-sdk = { version = "0.4.1" } matrix-sdk = { version = "0.4.1" }
refinery = { version = "0.6", features = ["rusqlite"]} refinery = { version = "0.8", features = ["rusqlite"]}
barrel = { version = "0.6", features = ["sqlite3"] } barrel = { version = "0.7", features = ["sqlite3"] }
strum = { version = "0.22", features = ["derive"] }
tempfile = "3" tempfile = "3"
substring = "1.4" substring = "1.4"
fuse-rust = "0.2" fuse-rust = "0.2"

View File

@ -0,0 +1,22 @@
use crate::systems::GameSystem;
use barrel::backend::Sqlite;
use barrel::{types, types::Type, Migration};
use itertools::Itertools;
use strum::IntoEnumIterator;
fn primary_id() -> Type {
types::text().unique(true).primary(true).nullable(false)
}
pub fn migration() -> String {
let mut m = Migration::new();
//Normally we would add a CHECK clause here, but types::custom requires a 'static string.
//Which means we can't automagically generate one from the enum.
m.create_table("room_info", move |t| {
t.add_column("room_id", primary_id());
t.add_column("game_system", types::text().nullable(false));
});
m.make::<Sqlite>()
}

View File

@ -1,2 +1 @@
use refinery::include_migration_mods;
include_migration_mods!("src/db/sqlite/migrator/migrations");

View File

@ -5,7 +5,7 @@ use sqlx::ConnectOptions;
use std::str::FromStr; use std::str::FromStr;
use thiserror::Error; use thiserror::Error;
pub mod migrations; //pub mod migrations;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum MigrationError { pub enum MigrationError {
@ -16,6 +16,11 @@ pub enum MigrationError {
RefineryError(#[from] refinery::Error), RefineryError(#[from] refinery::Error),
} }
mod embedded {
use refinery::embed_migrations;
embed_migrations!("src/db/sqlite/migrator/migrations");
}
/// Run database migrations against the sqlite database. /// Run database migrations against the sqlite database.
pub async fn migrate(db_path: &str) -> Result<(), MigrationError> { pub async fn migrate(db_path: &str) -> Result<(), MigrationError> {
//Create database if missing. //Create database if missing.
@ -28,6 +33,6 @@ pub async fn migrate(db_path: &str) -> Result<(), MigrationError> {
let mut conn = Config::new(ConfigDbType::Sqlite).set_db_path(db_path); let mut conn = Config::new(ConfigDbType::Sqlite).set_db_path(db_path);
info!("Running migrations"); info!("Running migrations");
migrations::runner().run(&mut conn)?; embedded::migrations::runner().run(&mut conn)?;
Ok(()) Ok(())
} }

View File

@ -14,3 +14,4 @@ pub mod models;
mod parser; mod parser;
pub mod rpc; pub mod rpc;
pub mod state; pub mod state;
pub mod systems;

View File

@ -0,0 +1,21 @@
use strum::{AsRefStr, Display, EnumIter, EnumString};
#[derive(EnumString, EnumIter, AsRefStr, Display)]
pub(crate) enum GameSystem {
ChroniclesOfDarkness,
Changeling,
MageTheAwakening,
WerewolfTheForsaken,
DeviantTheRenegades,
MummyTheCurse,
PrometheanTheCreated,
CallOfCthulhu,
DungeonsAndDragons5e,
DungeonsAndDragons4e,
DungeonsAndDragons35e,
DungeonsAndDragons2e,
DungeonsAndDragons1e,
None,
}
impl GameSystem {}