Fix db inconsistencies when deleting a room

Since the euph_trees table can't have any foreign key constraints
pointing to the euph_rooms table, deleting a room wouldn't delete that
room's trees in euph_trees. Upon reconnecting to the room, those trees
would then be displayed as placeholder messages without children.
This commit is contained in:
Joscha 2022-08-07 00:53:11 +02:00
parent a2b9f57a09
commit f430b0efc7
3 changed files with 15 additions and 3 deletions

View file

@ -472,13 +472,25 @@ impl EuphRequest {
}
fn delete(conn: &mut Connection, room: String) -> rusqlite::Result<()> {
conn.execute(
let tx = conn.transaction()?;
tx.execute(
"
DELETE FROM euph_rooms
WHERE room = ?
",
[room],
[&room],
)?;
tx.execute(
"
DELETE FROM euph_trees
WHERE room = ?
",
[&room],
)?;
tx.commit()?;
Ok(())
}

View file

@ -4,7 +4,6 @@ pub fn prepare(conn: &mut Connection) -> rusqlite::Result<()> {
println!("Opening vault");
// This temporary table has no foreign key constraint on euph_rooms since
// cross-schema constraints like that are not supported by SQLite.
// TODO Remove entries from this table whenever a room is deleted
conn.execute_batch(
"
CREATE TEMPORARY TABLE euph_trees (