Skip to content

Commit ea6366a

Browse files
Run SQL for stages
Run SQL to add stages table and update sets to reference stage_id.
1 parent a5ecedf commit ea6366a

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

src/integrations/supabase/types.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export type Database = {
434434
festival_edition_id: string
435435
id: string
436436
name: string
437-
stage: string | null
437+
stage_id: string | null
438438
time_end: string | null
439439
time_start: string | null
440440
updated_at: string
@@ -446,7 +446,7 @@ export type Database = {
446446
festival_edition_id: string
447447
id?: string
448448
name: string
449-
stage?: string | null
449+
stage_id?: string | null
450450
time_end?: string | null
451451
time_start?: string | null
452452
updated_at?: string
@@ -458,7 +458,7 @@ export type Database = {
458458
festival_edition_id?: string
459459
id?: string
460460
name?: string
461-
stage?: string | null
461+
stage_id?: string | null
462462
time_end?: string | null
463463
time_start?: string | null
464464
updated_at?: string
@@ -473,6 +473,30 @@ export type Database = {
473473
},
474474
]
475475
}
476+
stages: {
477+
Row: {
478+
created_at: string
479+
festival_edition_id: string
480+
id: string
481+
name: string
482+
updated_at: string
483+
}
484+
Insert: {
485+
created_at?: string
486+
festival_edition_id: string
487+
id?: string
488+
name: string
489+
updated_at?: string
490+
}
491+
Update: {
492+
created_at?: string
493+
festival_edition_id?: string
494+
id?: string
495+
name?: string
496+
updated_at?: string
497+
}
498+
Relationships: []
499+
}
476500
votes: {
477501
Row: {
478502
artist_id: string
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
-- Create stages table
2+
CREATE TABLE public.stages (
3+
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
4+
name TEXT NOT NULL,
5+
festival_edition_id UUID NOT NULL,
6+
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
7+
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
8+
);
9+
10+
-- Enable RLS
11+
ALTER TABLE public.stages ENABLE ROW LEVEL SECURITY;
12+
13+
-- Create policies
14+
CREATE POLICY "Anyone can view stages"
15+
ON public.stages
16+
FOR SELECT
17+
USING (true);
18+
19+
CREATE POLICY "Admins can manage stages"
20+
ON public.stages
21+
FOR ALL
22+
USING (is_admin(auth.uid()));
23+
24+
-- Add stage_id to sets table
25+
ALTER TABLE public.sets
26+
ADD COLUMN stage_id UUID;
27+
28+
-- Get the active festival edition ID
29+
DO $$
30+
DECLARE
31+
edition_id UUID;
32+
BEGIN
33+
SELECT id INTO edition_id FROM festival_editions WHERE is_active = true LIMIT 1;
34+
35+
IF edition_id IS NOT NULL THEN
36+
-- Insert Boom Festival 2025 stages
37+
INSERT INTO public.stages (name, festival_edition_id) VALUES
38+
('Dance Temple', edition_id),
39+
('Alchemy Circle', edition_id),
40+
('Chill Out Gardens', edition_id),
41+
('Liminal Village', edition_id),
42+
('Sacred Fire', edition_id),
43+
('Ambient Forest', edition_id);
44+
45+
-- Update existing sets to reference stage_id
46+
UPDATE public.sets
47+
SET stage_id = stages.id
48+
FROM public.stages
49+
WHERE sets.stage = stages.name
50+
AND stages.festival_edition_id = edition_id;
51+
END IF;
52+
END $$;
53+
54+
-- Remove the old stage text column
55+
ALTER TABLE public.sets DROP COLUMN stage;
56+
57+
-- Create trigger for timestamps
58+
CREATE TRIGGER update_stages_updated_at
59+
BEFORE UPDATE ON public.stages
60+
FOR EACH ROW
61+
EXECUTE FUNCTION public.update_updated_at_column();

0 commit comments

Comments
 (0)