Add a game system column to room info (#95)

Adds a new enum and table in preparation for storing game information about a specific room.

Reviewed-on: #95
master
projectmoon 6 months ago
parent c514b85510
commit 552daa4746
  1. 612
      Cargo.lock
  2. 5
      dicebot/Cargo.toml
  3. 22
      dicebot/src/db/sqlite/migrator/migrations/V10__add_game_system.rs
  4. 3
      dicebot/src/db/sqlite/migrator/migrations/mod.rs
  5. 9
      dicebot/src/db/sqlite/migrator/mod.rs
  6. 1
      dicebot/src/lib.rs
  7. 21
      dicebot/src/systems/mod.rs

612
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -33,8 +33,9 @@ futures = "0.3"
html2text = "0.2"
phf = { version = "0.8", features = ["macros"] }
matrix-sdk = { version = "0.4.1" }
refinery = { version = "0.6", features = ["rusqlite"]}
barrel = { version = "0.6", features = ["sqlite3"] }
refinery = { version = "0.8", features = ["rusqlite"]}
barrel = { version = "0.7", features = ["sqlite3"] }
strum = { version = "0.22", features = ["derive"] }
tempfile = "3"
substring = "1.4"
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 thiserror::Error;
pub mod migrations;
//pub mod migrations;
#[derive(Error, Debug)]
pub enum MigrationError {
@ -16,6 +16,11 @@ pub enum MigrationError {
RefineryError(#[from] refinery::Error),
}
mod embedded {
use refinery::embed_migrations;
embed_migrations!("src/db/sqlite/migrator/migrations");
}
/// Run database migrations against the sqlite database.
pub async fn migrate(db_path: &str) -> Result<(), MigrationError> {
//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);
info!("Running migrations");
migrations::runner().run(&mut conn)?;
embedded::migrations::runner().run(&mut conn)?;
Ok(())
}

@ -14,3 +14,4 @@ pub mod models;
mod parser;
pub mod rpc;
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…
Cancel
Save