-- =========================================================
-- TABLERO CDC - HABILITAR SUPABASE REALTIME
-- Ejecutar una sola vez en Supabase SQL Editor.
-- Incluye proyectos, links y listas dinámicas.
-- =========================================================

do $$
begin
  if not exists (
    select 1
    from pg_publication_tables
    where pubname = 'supabase_realtime'
      and schemaname = 'public'
      and tablename = 'projects'
  ) then
    alter publication supabase_realtime add table public.projects;
  end if;

  if not exists (
    select 1
    from pg_publication_tables
    where pubname = 'supabase_realtime'
      and schemaname = 'public'
      and tablename = 'project_links'
  ) then
    alter publication supabase_realtime add table public.project_links;
  end if;

  if not exists (
    select 1
    from pg_publication_tables
    where pubname = 'supabase_realtime'
      and schemaname = 'public'
      and tablename = 'app_lists'
  ) then
    alter publication supabase_realtime add table public.app_lists;
  end if;
end $$;
