Add a game system column to room info (#95)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Adds a new enum and table in preparation for storing game information about a specific room. Reviewed-on: #95
This commit is contained in:
parent
c514b85510
commit
552daa4746
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||||
|
|
|
@ -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>()
|
||||||
|
}
|
|
@ -1,2 +1 @@
|
||||||
use refinery::include_migration_mods;
|
|
||||||
include_migration_mods!("src/db/sqlite/migrator/migrations");
|
|
||||||
|
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 {}
|
Loading…
Reference in New Issue