-- Database Schema Update for MP3 Audio Support
-- This migration adds audio columns to the blog_messages table

-- Add audio_url column (nullable text field for storing the public URL)
ALTER TABLE blog_messages 
ADD COLUMN IF NOT EXISTS audio_url TEXT;

-- Add audio_duration column (nullable integer for duration in seconds)
ALTER TABLE blog_messages 
ADD COLUMN IF NOT EXISTS audio_duration INTEGER;

-- Create index for faster queries on posts with audio
CREATE INDEX IF NOT EXISTS idx_blog_messages_audio 
ON blog_messages(audio_url) 
WHERE audio_url IS NOT NULL;

-- Storage bucket configuration (run in Supabase Dashboard SQL Editor)
-- Note: Bucket is created programmatically via the API

-- RLS Policy for audio files (if needed in future)
-- For now, audio files are publicly readable via the podcast-audio bucket

COMMENT ON COLUMN blog_messages.audio_url IS 'Public URL to the audio file in Supabase Storage';
COMMENT ON COLUMN blog_messages.audio_duration IS 'Audio duration in seconds (estimated from file size)';