Clean up the database schema

This commit is contained in:
Savanni D'Gerinel 2024-11-30 18:55:51 -05:00
parent d8ea2aac40
commit 82c8f3f96e
2 changed files with 28 additions and 17 deletions

View File

@ -1,9 +1,12 @@
CREATE TABLE game( CREATE TABLE games(
uuid TEXT PRIMARY KEY uuid TEXT PRIMARY KEY,
name TEXT
); );
CREATE TABLE charsheet( CREATE TABLE characters(
uuid TEXT PRIMARY KEY, uuid TEXT PRIMARY KEY,
gametype TEXT NOT NULL, game TEXT,
data TEXT data TEXT,
FOREIGN KEY(game) REFERENCES games(uuid)
); );

View File

@ -89,6 +89,25 @@ pub struct DiskDb {
conn: Connection, conn: Connection,
} }
fn setup_test_database(conn: &Connection) {
let mut gamecount_stmt = conn.prepare("SELECT count(*) FROM games").unwrap();
let mut count = gamecount_stmt.query([]).unwrap();
if count.next().unwrap().unwrap().get::<usize, usize>(0) == Ok(0) {
let game_id = format!("{}", Uuid::new_v4());
let char_id = CharacterId::new();
let mut game_stmt = conn.prepare("INSERT INTO games VALUES (?, ?)").unwrap();
game_stmt.execute((game_id.clone(), "Circle of Bluest Sky"));
let mut sheet_stmt = conn
.prepare("INSERT INTO characters VALUES (?, ?, ?)")
.unwrap();
sheet_stmt.execute((char_id.as_str(), game_id, r#"{ "type_": "Candela", "name": "Soren Jensen", "pronouns": "he/him", "circle": "Circle of the Bluest Sky", "style": "dapper gentleman", "catalyst": "a cursed book", "question": "What were the contents of that book?", "nerve": { "type_": "nerve", "drives": { "current": 1, "max": 2 }, "resistances": { "current": 0, "max": 3 }, "move": { "gilded": false, "score": 2 }, "strike": { "gilded": false, "score": 1 }, "control": { "gilded": true, "score": 0 } }, "cunning": { "type_": "cunning", "drives": { "current": 1, "max": 1 }, "resistances": { "current": 0, "max": 3 }, "sway": { "gilded": false, "score": 0 }, "read": { "gilded": false, "score": 0 }, "hide": { "gilded": false, "score": 0 } }, "intuition": { "type_": "intuition", "drives": { "current": 0, "max": 0 }, "resistances": { "current": 0, "max": 3 }, "survey": { "gilded": false, "score": 0 }, "focus": { "gilded": false, "score": 0 }, "sense": { "gilded": false, "score": 0 } }, "role": "Slink", "role_abilities": [ "Scout: If you have time to observe a location, you can spend 1 Intuition to ask a question: What do I notice here that others do not see? What in this place might be of use to us? What path should we follow?" ], "specialty": "Detective", "specialty_abilities": [ "Mind Palace: When you want to figure out how two clues might relate or what path they should point you towards, burn 1 Intution resistance. The GM will give you the information you have deduced." ] }"#))
.unwrap();
}
}
impl DiskDb { impl DiskDb {
pub fn new<P>(path: Option<P>) -> Result<Self, Error> pub fn new<P>(path: Option<P>) -> Result<Self, Error>
where where
@ -100,18 +119,7 @@ impl DiskDb {
}; };
MIGRATIONS.to_latest(&mut conn).expect("to run migrations"); MIGRATIONS.to_latest(&mut conn).expect("to run migrations");
{ setup_test_database(&conn);
let mut stmt = conn.prepare("SELECT count(*) FROM charsheet").unwrap();
let mut sheets = stmt.query([]).unwrap();
if sheets.next().unwrap().unwrap().get::<usize, usize>(0) == Ok(0) {
let char_id = CharacterId::new();
let mut stmt = conn
.prepare("INSERT INTO charsheet VALUES (?, ?, ?)")
.unwrap();
stmt.execute((char_id.as_str(), "Candela", r#"{ "type_": "Candela", "name": "Soren Jensen", "pronouns": "he/him", "circle": "Circle of the Bluest Sky", "style": "dapper gentleman", "catalyst": "a cursed book", "question": "What were the contents of that book?", "nerve": { "type_": "nerve", "drives": { "current": 1, "max": 2 }, "resistances": { "current": 0, "max": 3 }, "move": { "gilded": false, "score": 2 }, "strike": { "gilded": false, "score": 1 }, "control": { "gilded": true, "score": 0 } }, "cunning": { "type_": "cunning", "drives": { "current": 1, "max": 1 }, "resistances": { "current": 0, "max": 3 }, "sway": { "gilded": false, "score": 0 }, "read": { "gilded": false, "score": 0 }, "hide": { "gilded": false, "score": 0 } }, "intuition": { "type_": "intuition", "drives": { "current": 0, "max": 0 }, "resistances": { "current": 0, "max": 3 }, "survey": { "gilded": false, "score": 0 }, "focus": { "gilded": false, "score": 0 }, "sense": { "gilded": false, "score": 0 } }, "role": "Slink", "role_abilities": [ "Scout: If you have time to observe a location, you can spend 1 Intuition to ask a question: What do I notice here that others do not see? What in this place might be of use to us? What path should we follow?" ], "specialty": "Detective", "specialty_abilities": [ "Mind Palace: When you want to figure out how two clues might relate or what path they should point you towards, burn 1 Intution resistance. The GM will give you the information you have deduced." ] }"#))
.unwrap();
}
}
Ok(DiskDb { conn }) Ok(DiskDb { conn })
} }