From 80ae3cd85a7bfd9e3a83bc0de7f271f58ec491be Mon Sep 17 00:00:00 2001 From: "Roberto.silva" Date: Tue, 17 Mar 2026 14:51:12 -0600 Subject: [PATCH] Se divide en dos migraciones para manejar el orden --- ...60317202431_rules_criterios_evaluacion.sql | 73 ++----------------- 1 file changed, 5 insertions(+), 68 deletions(-) diff --git a/supabase/migrations/20260317202431_rules_criterios_evaluacion.sql b/supabase/migrations/20260317202431_rules_criterios_evaluacion.sql index e97b98b..f91070f 100644 --- a/supabase/migrations/20260317202431_rules_criterios_evaluacion.sql +++ b/supabase/migrations/20260317202431_rules_criterios_evaluacion.sql @@ -1,10 +1,8 @@ - - CREATE OR REPLACE FUNCTION public.suma_porcentajes(jsonb) - RETURNS numeric - LANGUAGE plpgsql - IMMUTABLE -AS $function$ +RETURNS numeric +LANGUAGE plpgsql +IMMUTABLE +AS $$ declare total numeric; begin @@ -14,65 +12,4 @@ begin return total; end; -$function$ -; - -CREATE OR REPLACE FUNCTION public.validar_prerrequisito_asignatura() - RETURNS trigger - LANGUAGE plpgsql -AS $function$ -declare - v_plan uuid; - v_ciclo integer; -begin - - if new.prerrequisito_asignatura_id is null then - return new; - end if; - - select - plan_estudio_id, - numero_ciclo - into - v_plan, - v_ciclo - from public.asignaturas - where id = new.prerrequisito_asignatura_id; - - if not found then - raise exception - 'La asignatura prerrequisito no existe'; - end if; - - if v_plan <> new.plan_estudio_id then - raise exception - 'El prerrequisito debe pertenecer al mismo plan de estudio'; - end if; - - if new.numero_ciclo is null then - raise exception - 'La asignatura debe tener numero_ciclo definido'; - end if; - - if v_ciclo is null then - raise exception - 'El prerrequisito debe tener numero_ciclo definido'; - end if; - - if v_ciclo >= new.numero_ciclo then - raise exception - 'El prerrequisito debe pertenecer a un ciclo menor'; - end if; - - return new; - -end; -$function$ -; - - -alter table "public"."asignaturas" add constraint "asignaturas_criterios_porcentaje_max_100" CHECK ((public.suma_porcentajes(criterios_de_evaluacion) <= (100)::numeric)) not valid; - -alter table "public"."asignaturas" validate constraint "asignaturas_criterios_porcentaje_max_100"; - -set check_function_bodies = off; \ No newline at end of file +$$; \ No newline at end of file