alter type "public"."tipo_cambio" rename to "tipo_cambio__old_version_to_be_dropped"; create type "public"."tipo_cambio" as enum ('ACTUALIZACION_CAMPO', 'ACTUALIZACION_MAPA', 'TRANSICION_ESTADO', 'OTRO', 'CREACION'); alter table "public"."cambios_asignatura" alter column tipo type "public"."tipo_cambio" using tipo::text::"public"."tipo_cambio"; alter table "public"."cambios_plan" alter column tipo type "public"."tipo_cambio" using tipo::text::"public"."tipo_cambio"; drop type "public"."tipo_cambio__old_version_to_be_dropped"; set check_function_bodies = off; create or replace view "public"."plantilla_plan" as SELECT plan.id AS plan_estudio_id, struct.id AS estructura_id, struct.template_id FROM (public.planes_estudio plan JOIN public.estructuras_plan struct ON ((plan.estructura_id = struct.id))); 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$ ;