-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_job_tables.sql
More file actions
56 lines (48 loc) · 1.69 KB
/
reset_job_tables.sql
File metadata and controls
56 lines (48 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- Complete reset of CompletedJob and FailedJob tables
-- WARNING: This will delete ALL data in these tables!
-- Run this in your PostgreSQL 'jobs' database
-- First, check what exists
SELECT 'Before cleanup - CompletedJob partitions:' as info;
SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename LIKE 'CompletedJob%';
SELECT 'Before cleanup - FailedJob partitions:' as info;
SELECT tablename FROM pg_tables WHERE schemaname = 'public' AND tablename LIKE 'FailedJob%';
-- Drop all CompletedJob partitions explicitly (in case they're orphaned)
DO $$
DECLARE
tbl TEXT;
BEGIN
FOR tbl IN
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public'
AND tablename LIKE 'CompletedJob_%'
LOOP
EXECUTE 'DROP TABLE IF EXISTS "' || tbl || '" CASCADE';
RAISE NOTICE 'Dropped: %', tbl;
END LOOP;
END $$;
-- Drop all FailedJob partitions explicitly (in case they're orphaned)
DO $$
DECLARE
tbl TEXT;
BEGIN
FOR tbl IN
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public'
AND tablename LIKE 'FailedJob_%'
LOOP
EXECUTE 'DROP TABLE IF EXISTS "' || tbl || '" CASCADE';
RAISE NOTICE 'Dropped: %', tbl;
END LOOP;
END $$;
-- Drop the parent tables (this will cascade to any remaining partitions)
DROP TABLE IF EXISTS "CompletedJob" CASCADE;
DROP TABLE IF EXISTS "FailedJob" CASCADE;
-- Verify everything is dropped
SELECT 'After cleanup - Tables remaining:' as info;
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public'
AND (tablename LIKE 'CompletedJob%' OR tablename LIKE 'FailedJob%');
-- Now restart your application and it will recreate the tables with correct partitions