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

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Slowed down room history download speed - Slowed down room history download speed
### Fixed ### Fixed
- Chat rendering when deleting and re-joining a room
- Spacing in some popups - Spacing in some popups
## v0.1.0 - 2022-08-06 ## v0.1.0 - 2022-08-06

View file

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

View file

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