
  create table "public"."tabla_prueba" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "columna_prueba" text
      );


alter table "public"."tabla_prueba" enable row level security;

CREATE UNIQUE INDEX tabla_prueba_pkey ON public.tabla_prueba USING btree (id);

alter table "public"."tabla_prueba" add constraint "tabla_prueba_pkey" PRIMARY KEY using index "tabla_prueba_pkey";

set check_function_bodies = off;

CREATE OR REPLACE FUNCTION public.set_actualizado_en()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
begin
  new.actualizado_en = now();
  return new;
end;
$function$
;

CREATE OR REPLACE FUNCTION public.unaccent_immutable(text)
 RETURNS text
 LANGUAGE sql
 IMMUTABLE PARALLEL SAFE STRICT
AS $function$
  SELECT public.unaccent('public.unaccent', $1);
$function$
;

CREATE OR REPLACE FUNCTION public.validar_numero_ciclo_asignatura()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
declare
  v_numero_ciclos int;
begin
  if new.numero_ciclo is null then
    return new;
  end if;

  select pe.numero_ciclos into v_numero_ciclos
  from planes_estudio pe
  where pe.id = new.plan_estudio_id;

  if v_numero_ciclos is null then
    raise exception 'plan_estudio_id inválido %, plan no encontrado', new.plan_estudio_id;
  end if;

  if new.numero_ciclo < 1 then
    raise exception 'numero_ciclo debe ser >= 1 (recibido %)', new.numero_ciclo;
  end if;

  if new.numero_ciclo > v_numero_ciclos then
    raise exception 'numero_ciclo % excede planes_estudio.numero_ciclos % para plan_estudio_id %',
      new.numero_ciclo, v_numero_ciclos, new.plan_estudio_id;
  end if;

  return new;
end;
$function$
;

grant delete on table "public"."tabla_prueba" to "anon";

grant insert on table "public"."tabla_prueba" to "anon";

grant references on table "public"."tabla_prueba" to "anon";

grant select on table "public"."tabla_prueba" to "anon";

grant trigger on table "public"."tabla_prueba" to "anon";

grant truncate on table "public"."tabla_prueba" to "anon";

grant update on table "public"."tabla_prueba" to "anon";

grant delete on table "public"."tabla_prueba" to "authenticated";

grant insert on table "public"."tabla_prueba" to "authenticated";

grant references on table "public"."tabla_prueba" to "authenticated";

grant select on table "public"."tabla_prueba" to "authenticated";

grant trigger on table "public"."tabla_prueba" to "authenticated";

grant truncate on table "public"."tabla_prueba" to "authenticated";

grant update on table "public"."tabla_prueba" to "authenticated";

grant delete on table "public"."tabla_prueba" to "postgres";

grant insert on table "public"."tabla_prueba" to "postgres";

grant references on table "public"."tabla_prueba" to "postgres";

grant select on table "public"."tabla_prueba" to "postgres";

grant trigger on table "public"."tabla_prueba" to "postgres";

grant truncate on table "public"."tabla_prueba" to "postgres";

grant update on table "public"."tabla_prueba" to "postgres";

grant delete on table "public"."tabla_prueba" to "service_role";

grant insert on table "public"."tabla_prueba" to "service_role";

grant references on table "public"."tabla_prueba" to "service_role";

grant select on table "public"."tabla_prueba" to "service_role";

grant trigger on table "public"."tabla_prueba" to "service_role";

grant truncate on table "public"."tabla_prueba" to "service_role";

grant update on table "public"."tabla_prueba" to "service_role";


