fix: guest_activity follows a workspace rename and goes with a workspace delete

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BayTppRCstWX6qTf3LMco5
This commit is contained in:
Ruben Fiszel
2026-09-04 14:30:30 +02:00
co-authored by Claude Fable 5.1
parent cb5d00b83b
commit 6169076d70
2 changed files with 25 additions and 0 deletions
+13
View File
@@ -623,6 +623,12 @@ async fn a_workspace_rename_keeps_the_guest_switch(db: Pool<Postgres>) -> anyhow
let port = server.addr.port();
enable_guests(port, "test-workspace").await?;
sqlx::query(
"INSERT INTO guest_activity (email, workspace_id, day)
VALUES ('guest@example.com', 'test-workspace', CURRENT_DATE)",
)
.execute(&db)
.await?;
let resp = authed(
client().post(format!(
"http://localhost:{port}/api/w/test-workspace/workspaces/change_workspace_id"
@@ -639,6 +645,13 @@ async fn a_workspace_rename_keeps_the_guest_switch(db: Pool<Postgres>) -> anyhow
.fetch_one(&db)
.await?;
assert!(enabled, "the guest switch travels with the workspace");
let moved: bool = sqlx::query_scalar(
"SELECT EXISTS(SELECT 1 FROM guest_activity WHERE workspace_id = 'test-workspace-2')
AND NOT EXISTS(SELECT 1 FROM guest_activity WHERE workspace_id = 'test-workspace')",
)
.fetch_one(&db)
.await?;
assert!(moved, "the guests seen in the workspace follow its new id");
Ok(())
}
@@ -187,6 +187,13 @@ pub(crate) async fn change_workspace_id(
.execute(&mut *tx)
.await?;
info!("Updating guest_activity table");
sqlx::query("UPDATE guest_activity SET workspace_id = $1 WHERE workspace_id = $2")
.bind(&rw.new_id)
.bind(&old_id)
.execute(&mut *tx)
.await?;
info!("Updating workspace_invite table");
sqlx::query!(
"UPDATE workspace_invite SET workspace_id = $1 WHERE workspace_id = $2",
@@ -1112,6 +1119,11 @@ pub(crate) async fn delete_workspace(
.execute(&mut *tx)
.await?;
sqlx::query("DELETE FROM guest_activity WHERE workspace_id = $1")
.bind(&w_id)
.execute(&mut *tx)
.await?;
sqlx::query!("DELETE FROM token WHERE workspace_id = $1", &w_id)
.execute(&mut *tx)
.await?;