Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions crates/buzz-db/src/store/deletion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub const PENDING_SCOPED_TABLES: &[&str] = &[
"identity_retirement_actions",
"identity_retirement_holds",
"identity_retirement_workflows",
"outbox",
"thread_heads",
];

Expand All @@ -184,6 +185,7 @@ pub const APPROVAL_FORWARD_TABLES: &[&str] = &[
"identity_retirement_actions",
"identity_retirement_holds",
"identity_retirement_workflows",
"outbox",
"search_backfill",
"search_outbox",
"thread_heads",
Expand Down Expand Up @@ -9620,6 +9622,17 @@ DROP FUNCTION protect_community_deletion_manifest_keys();
#[tokio::test]
#[ignore = "requires Postgres"]
async fn pending_scoped_tables_are_optional_purged_and_verified() {
// Named here, not read from the production list, so a missing or
// misspelled entry fails this test.
const PENDING: [&str; 6] = [
"channel_heads",
"identity_retirement_actions",
"identity_retirement_holds",
"identity_retirement_workflows",
"outbox",
"thread_heads",
];
assert_eq!(PENDING_SCOPED_TABLES, PENDING);
let (_, scratch) = scratch_desired_state_database("deletion_pending").await;
let db = Db::new(&DbConfig {
database_url: scratch.url().to_owned(),
Expand All @@ -9644,7 +9657,7 @@ DROP FUNCTION protect_community_deletion_manifest_keys();
.as_uuid();

// The expand migration lands after the request was inventoried.
for table in PENDING_SCOPED_TABLES {
for table in PENDING {
sqlx::query(AssertSqlSafe(format!(
"CREATE TABLE {table} (community_id UUID NOT NULL)"
)))
Expand Down Expand Up @@ -9709,16 +9722,16 @@ DROP FUNCTION protect_community_deletion_manifest_keys();
.await
.expect("bindings");
let deleted = store.purge_postgres(&token).await.expect("purge postgres");
for table in PENDING_SCOPED_TABLES {
assert_eq!(deleted.get(*table), Some(&1), "{table}");
for table in PENDING {
assert_eq!(deleted.get(table), Some(&1), "{table}");
}
store
.mark_cache_purged(&token, serde_json::json!({"keys": 0}))
.await
.expect("cache");

// Verification covers the pending tables too: a straggler fails it.
for table in PENDING_SCOPED_TABLES {
for table in PENDING {
let insert = format!("INSERT INTO {table} (community_id) VALUES ($1)");
sqlx::query(AssertSqlSafe(insert))
.bind(community)
Expand All @@ -9741,7 +9754,7 @@ DROP FUNCTION protect_community_deletion_manifest_keys();
.verify_postgres_logically_deleted(&token)
.await
.expect("verify");
for table in PENDING_SCOPED_TABLES {
for table in PENDING {
let kept: i64 = sqlx::query_scalar(AssertSqlSafe(format!(
"SELECT count(*) FROM {table} WHERE community_id = $1"
)))
Expand Down
Loading