-- =========================================================
-- 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 = 'tablero_cdc_projects'
  ) then
    alter publication supabase_realtime add table public.tablero_cdc_projects;
  end if;

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

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