-- This snippet checks if the messages table is already part of the publication before attempting to add it. -- Enable replication for the messages table ALTER TABLE public.messages REPLICA IDENTITY FULL; -- Check if the messages table is already part of the publication DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_publication_tables WHERE pubname = 'supabase_realtime' AND schemaname = 'public' AND tablename = 'messages' ) THEN ALTER PUBLICATION supabase_realtime ADD TABLE public.messages; END IF; END $$;