test(integration): pre-clean BroadcastOrgRoot fixtures to avoid unique-index collision #2123

Closed
core-be wants to merge 1 commits from fix/broadcast-org-root-test-cleanup into main
@@ -70,6 +70,19 @@ func integrationDB_BroadcastOrgRoot(t *testing.T) *sql.DB {
t.Fatalf("ping: %v", err)
}
t.Cleanup(func() { conn.Close() })
// Defensive: ensure the partial-unique index exists so the test
// exercises real constraint behaviour (not a silently-missing index).
if _, err := conn.ExecContext(context.Background(), `
CREATE UNIQUE INDEX IF NOT EXISTS workspaces_parent_name_uniq
ON workspaces (
COALESCE(parent_id, '00000000-0000-0000-0000-000000000000'::uuid),
name
)
WHERE status != 'removed'
`); err != nil {
t.Fatalf("ensure constraint: %v", err)
}
return conn
}
@@ -88,6 +101,13 @@ func TestIntegration_BroadcastOrgRoot_NonRootSenderResolvesToRoot(t *testing.T)
ctx := context.Background()
prefix := fmt.Sprintf("itest-bcastroot-%s", uuid.New().String()[:8])
// Pre-test cleanup: remove any stale rows left by a prior crashed run
// so the fixture INSERTs below don't hit the partial-unique index.
if _, err := conn.ExecContext(ctx,
`DELETE FROM workspaces WHERE name LIKE $1`, prefix+"%"); err != nil {
t.Logf("pre-test cleanup (non-fatal): %v", err)
}
t.Cleanup(func() {
if _, err := conn.ExecContext(ctx,
`DELETE FROM workspaces WHERE name LIKE $1`, prefix+"%"); err != nil {