-- Create Analytics Storage Bucket
-- Run this in Supabase SQL Editor

-- 1. Create a public storage bucket for analytics data
INSERT INTO storage.buckets (id, name, public)
VALUES ('analytics-data', 'analytics-data', true)
ON CONFLICT (id) DO NOTHING;

-- 2. Allow public read access (for API to fetch data)
CREATE POLICY "Allow public read access on analytics-data"
ON storage.objects FOR SELECT
USING (bucket_id = 'analytics-data');

-- 3. Allow authenticated upsert (for API to write data)  
CREATE POLICY "Allow public insert on analytics-data"
ON storage.objects FOR INSERT
WITH CHECK (bucket_id = 'analytics-data');

CREATE POLICY "Allow public update on analytics-data"
ON storage.objects FOR UPDATE
USING (bucket_id = 'analytics-data');

CREATE POLICY "Allow public delete on analytics-data"
ON storage.objects FOR DELETE
USING (bucket_id = 'analytics-data');

-- Verify bucket was created
SELECT * FROM storage.buckets WHERE id = 'analytics-data';
