11\set ON_ERROR_STOP true
22
3+ BEGIN ;
4+
35DO $$
46BEGIN
57 IF NOT EXISTS (
1012 END IF;
1113END $$;
1214
15+ -- Pre-lock all tables so that share background jobs can't sneak in and lock things mid transaction.
16+ -- Lock all tables in a single statement to prevent deadlocks
17+ LOCK TABLE
18+ users,
19+ superadmins,
20+ role_memberships,
21+ loose_code_roots,
22+ org_members,
23+ tours,
24+ projects,
25+ project_branches,
26+ project_releases,
27+ project_favorites,
28+ catalog_categories,
29+ project_categories,
30+ oauth_clients,
31+ contributions,
32+ contribution_status_events,
33+ comments,
34+ comment_revisions,
35+ tickets,
36+ teams,
37+ team_members,
38+ orgs,
39+ subjects,
40+ resources,
41+ causal_diff_queue,
42+ namespace_diffs,
43+ personal_keys,
44+ history_comments,
45+ history_comment_revisions,
46+ history_comment_revisions_project_discovery,
47+ namespace_ownership,
48+ causal_ownership,
49+ public .cloud_subscribers
50+ IN ACCESS EXCLUSIVE MODE;
51+
1352-- Resets most relevant tables, useful to run between tests.
1453-- Doesn't clean codebase tables since that just slows things down, but does clean out codebase ownership.
1554SET client_min_messages TO WARNING;
@@ -26,11 +65,6 @@ TRUNCATE TABLE project_favorites CASCADE;
2665TRUNCATE TABLE catalog_categories CASCADE;
2766TRUNCATE TABLE project_categories CASCADE;
2867TRUNCATE TABLE oauth_clients CASCADE;
29- TRUNCATE TABLE oauth_clients CASCADE;
30- TRUNCATE TABLE contributions CASCADE;
31- TRUNCATE TABLE contribution_status_events CASCADE;
32- TRUNCATE TABLE comments CASCADE;
33- TRUNCATE TABLE comment_revisions CASCADE;
3468TRUNCATE TABLE contributions CASCADE;
3569TRUNCATE TABLE contribution_status_events CASCADE;
3670TRUNCATE TABLE tickets CASCADE;
@@ -57,3 +91,5 @@ TRUNCATE TABLE causal_ownership CASCADE;
5791-- TRUNCATE TABLE causals CASCADE;
5892
5993TRUNCATE TABLE public .cloud_subscribers CASCADE;
94+
95+ COMMIT ;
0 commit comments