1
1
-- Replaced with Redis for webhook status tracking
2
2
DROP TABLE IF EXISTS public .webhook_process_status ;
3
3
4
- -- Replace materialized view with regular table for better performance
5
- -- Drop the materialized view and its indices first
6
- DROP MATERIALIZED VIEW IF EXISTS public .workflow_events_summary CASCADE;
7
-
8
4
-- Create workflow_runs table (replacing the materialized view)
9
5
-- This table will be directly upserted to by the webhook handler
10
6
CREATE TABLE IF NOT EXISTS public .workflow_runs (
@@ -55,6 +51,7 @@ CREATE INDEX idx_workflow_runs_unique_lookup ON public.workflow_runs USING btree
55
51
56
52
-- Backfill workflow_runs table with existing data from the materialized view
57
53
-- This preserves historical data before we drop the view
54
+ -- Join with repositories table to get repository_name (matching how the view was built)
58
55
INSERT INTO public .workflow_runs (
59
56
workflow_run_id,
60
57
class_id,
@@ -79,28 +76,35 @@ INSERT INTO public.workflow_runs (
79
76
updated_at
80
77
)
81
78
SELECT
82
- workflow_run_id,
83
- class_id,
84
- repository_name,
85
- workflow_name,
86
- workflow_path,
87
- head_sha,
88
- head_branch,
89
- run_number,
90
- run_attempt,
91
- actor_login,
92
- triggering_actor_login,
93
- assignment_id,
94
- profile_id,
95
- requested_at,
96
- in_progress_at,
97
- completed_at,
98
- conclusion,
99
- queue_time_seconds,
100
- run_time_seconds,
79
+ wes . workflow_run_id ,
80
+ wes . class_id ,
81
+ r . repository as repository_name, -- Get repository name from repositories table
82
+ wes . workflow_name ,
83
+ wes . workflow_path ,
84
+ wes . head_sha ,
85
+ wes . head_branch ,
86
+ wes . run_number ,
87
+ wes . run_attempt ,
88
+ wes . actor_login ,
89
+ wes . triggering_actor_login ,
90
+ wes . assignment_id ,
91
+ wes . profile_id ,
92
+ wes . requested_at ,
93
+ wes . in_progress_at ,
94
+ wes . completed_at ,
95
+ wes . conclusion ,
96
+ wes . queue_time_seconds ,
97
+ wes . run_time_seconds ,
101
98
NOW() as created_at,
102
99
NOW() as updated_at
103
- FROM public .workflow_events_summary
100
+ FROM public .workflow_events_summary wes
101
+ LEFT JOIN public .repositories r ON (
102
+ r .assignment_id = wes .assignment_id
103
+ AND (
104
+ (wes .profile_id IS NOT NULL AND r .profile_id = wes .profile_id )
105
+ OR (wes .profile_id IS NULL AND r .assignment_group_id IS NOT NULL )
106
+ )
107
+ )
104
108
ON CONFLICT ON CONSTRAINT workflow_runs_unique_run DO NOTHING;
105
109
106
110
-- Log the backfill results
@@ -320,7 +324,10 @@ CREATE TRIGGER trigger_maintain_workflow_runs
320
324
COMMENT ON TRIGGER trigger_maintain_workflow_runs ON public.workflow_events IS
321
325
' Maintains workflow_runs table in real-time by aggregating events as they arrive. Eliminates need for materialized view refreshes.' ;
322
326
323
- -- Update get_workflow_events_summary_for_class to use workflow_runs table
327
+ -- Drop public.get_workflow_events_summary_for_class function
328
+ DROP FUNCTION IF EXISTS public .get_workflow_events_summary_for_class (bigint );
329
+
330
+ -- Create new get_workflow_events_summary_for_class function
324
331
CREATE OR REPLACE FUNCTION public .get_workflow_events_summary_for_class(p_class_id bigint )
325
332
RETURNS SETOF public .workflow_runs
326
333
LANGUAGE plpgsql
@@ -590,6 +597,10 @@ COMMENT ON FUNCTION public.get_all_class_metrics() IS
590
597
-- Drop the now-obsolete refresh function and its scheduled job
591
598
DROP FUNCTION IF EXISTS public .refresh_workflow_events_summary ();
592
599
600
+ -- Replace materialized view with regular table for better performance
601
+ -- Drop the materialized view and its indices
602
+ DROP MATERIALIZED VIEW IF EXISTS public .workflow_events_summary CASCADE;
603
+
593
604
-- Drop the pg_cron job that was refreshing the materialized view every 5 minutes
594
605
DO $$
595
606
BEGIN
0 commit comments