-- Add attachment URL column to calendar_events
ALTER TABLE public.calendar_events
ADD COLUMN IF NOT EXISTS attachment_url text,
ADD COLUMN IF NOT EXISTS attachment_name text;

-- Create public bucket for calendar attachments (meeting notices, etc.)
INSERT INTO storage.buckets (id, name, public)
VALUES ('calendar-attachments', 'calendar-attachments', true)
ON CONFLICT (id) DO NOTHING;

-- Storage policies
CREATE POLICY "Calendar attachments are publicly viewable"
ON storage.objects FOR SELECT
USING (bucket_id = 'calendar-attachments');

CREATE POLICY "Authenticated users can upload calendar attachments"
ON storage.objects FOR INSERT
TO authenticated
WITH CHECK (bucket_id = 'calendar-attachments');

CREATE POLICY "Authenticated users can update calendar attachments"
ON storage.objects FOR UPDATE
TO authenticated
USING (bucket_id = 'calendar-attachments');

CREATE POLICY "Authenticated users can delete calendar attachments"
ON storage.objects FOR DELETE
TO authenticated
USING (bucket_id = 'calendar-attachments');