wetalk/supabase/migrations/009_scheduled_publishing.sql
ordinarthur 828b3b09e9
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 37s
add many things 2
2026-04-13 15:52:26 +02:00

30 lines
802 B
SQL

-- Scheduled publishing
ALTER TABLE podcasts ADD COLUMN published_at timestamptz;
-- Update the SELECT policy: podcasts are visible if:
-- 1. Not scheduled (published_at IS NULL)
-- 2. Scheduled time has passed (published_at <= now())
-- 3. Current user is the creator
-- Note: drop the existing select policy and recreate it
-- First find and drop existing select policies on podcasts
DO $$
DECLARE
pol RECORD;
BEGIN
FOR pol IN
SELECT policyname FROM pg_policies
WHERE tablename = 'podcasts' AND cmd = 'SELECT'
LOOP
EXECUTE format('DROP POLICY %I ON podcasts', pol.policyname);
END LOOP;
END $$;
CREATE POLICY "Podcasts visible when published or owned"
ON podcasts FOR SELECT
USING (
published_at IS NULL
OR published_at <= now()
OR creator_id = auth.uid()
);