acadia-2/issue/45 #60
@@ -89,33 +89,57 @@
|
||||
"npm": {
|
||||
"@deno/darwin-arm64@2.6.4": {
|
||||
"integrity": "sha512-5pocuV2IVWYUzomXze+bDSO86uX1WPxUn82BS7BrLI3ix8Eq7l8DhvYgz064w7rwCM4CiLLSc6MAQpAI+0gUag==",
|
||||
"os": ["darwin"],
|
||||
"cpu": ["arm64"]
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
]
|
||||
},
|
||||
"@deno/darwin-x64@2.6.4": {
|
||||
"integrity": "sha512-tX7Fz47HcoXTYR4wN2WzXjqJtEPTftzjEknCYkZa8D4BzvpN7Zo1ra3Jd6bWPN9+T6mgTL6YMPMMSigXddIUcA==",
|
||||
"os": ["darwin"],
|
||||
"cpu": ["x64"]
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
},
|
||||
"@deno/linux-arm64-glibc@2.6.4": {
|
||||
"integrity": "sha512-wY4hjjVLq5idClWj6e1de9IUZ0QZ1rxo16o0dwCJpMi+w1lolxtYxGF4y7pkcxAdZOpMGsXZuYMPq1Z2n51esA==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["arm64"]
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
]
|
||||
},
|
||||
"@deno/linux-x64-glibc@2.6.4": {
|
||||
"integrity": "sha512-H9b0WJw+eWyC6GcMGCXxC/3lz2kVveyWyUrzGyQ8hJmtDJpWiDnCU2iPqEpEcwXHgAUFFyjnRaFwedwwv5ApdA==",
|
||||
"os": ["linux"],
|
||||
"cpu": ["x64"]
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
},
|
||||
"@deno/win32-arm64@2.6.4": {
|
||||
"integrity": "sha512-fMH1dx54ORbCTpMorGjDshwonIu6KfgfPC+Pq+14jeq/8604EIFXiA484p3Ov+ViZycndNHEPe8ZKPNd8xLjJA==",
|
||||
"os": ["win32"],
|
||||
"cpu": ["arm64"]
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
]
|
||||
},
|
||||
"@deno/win32-x64@2.6.4": {
|
||||
"integrity": "sha512-hAxqNrBLHCINtqDgKcRiu8QtMbtdnHOVW3OFQjzA3gZEcpnGUK3JiF5ql++83SjuQH8ViZKGcdqkioLR7Bf14A==",
|
||||
"os": ["win32"],
|
||||
"cpu": ["x64"]
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"cpu": [
|
||||
"x64"
|
||||
]
|
||||
},
|
||||
"@isaacs/fs-minipass@4.0.1": {
|
||||
"integrity": "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==",
|
||||
@@ -352,7 +376,8 @@
|
||||
"dependencies": [
|
||||
"jsr:@david/dax@~0.44.2",
|
||||
"jsr:@openai/openai@^6.16.0",
|
||||
"jsr:@zod/zod@^4.3.5"
|
||||
"jsr:@zod/zod@^4.3.5",
|
||||
"jsr:@david/dax@~0.44.2"
|
||||
],
|
||||
"packageJson": {
|
||||
"dependencies": [
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { $ } from "@david/dax";
|
||||
|
||||
const OUT_FILE = "supabase/diffs/sql_para_remoto_como_local.sql";
|
||||
const OUT_FILE = "supabase/diffs/sql_para_local_como_remoto.sql";
|
||||
|
||||
console.log("🔍 Comparando base de datos local vs. remota...");
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
v2.72.7
|
||||
v2.75.0
|
||||
+167
-12
File diff suppressed because one or more lines are too long
@@ -0,0 +1,205 @@
|
||||
create extension if not exists "http" with schema "extensions";
|
||||
|
||||
alter table "public"."asignaturas" drop constraint "asignaturas_facultad_propietaria_id_fkey";
|
||||
|
||||
alter table "public"."cambios_plan" drop constraint "cambios_plan_plan_estudio_id_fkey";
|
||||
|
||||
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', 'ACTUALIZACION');
|
||||
|
||||
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";
|
||||
|
||||
alter table "public"."asignaturas" drop column "facultad_propietaria_id";
|
||||
|
||||
alter table "public"."asignaturas" add column "asignatura_hash" text generated always as (encode(SUBSTRING(extensions.digest((id)::text, 'sha512'::text) FROM 1 FOR 12), 'hex'::text)) stored;
|
||||
|
||||
alter table "public"."cambios_plan" drop column "interaccion_ia_id";
|
||||
|
||||
alter table "public"."cambios_plan" add column "response_id" text;
|
||||
|
||||
alter table "public"."planes_estudio" add column "conversation_id" text;
|
||||
|
||||
alter table "public"."planes_estudio" add column "plan_hash" text generated always as (encode(SUBSTRING(extensions.digest((id)::text, 'sha512'::text) FROM 1 FOR 12), 'hex'::text)) stored;
|
||||
|
||||
CREATE UNIQUE INDEX planes_estudio_conversation_id_key ON public.planes_estudio USING btree (conversation_id);
|
||||
|
||||
alter table "public"."planes_estudio" add constraint "planes_estudio_conversation_id_key" UNIQUE using index "planes_estudio_conversation_id_key";
|
||||
|
||||
set check_function_bodies = off;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.fn_log_cambios_planes_estudio()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$declare
|
||||
k text;
|
||||
old_val jsonb;
|
||||
new_val jsonb;
|
||||
|
||||
v_response_id text;
|
||||
begin
|
||||
v_response_id := nullif(new.meta_origen->>'response_id','');
|
||||
|
||||
-- INSERT -> CREACION
|
||||
if tg_op = 'INSERT' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.creado_por,
|
||||
'CREACION'::public.tipo_cambio,
|
||||
null,
|
||||
null,
|
||||
to_jsonb(new),
|
||||
null
|
||||
);
|
||||
|
||||
return new;
|
||||
end if;
|
||||
|
||||
-- DELETE (opcional): si no lo quieres, bórralo
|
||||
if tg_op = 'DELETE' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
old.id,
|
||||
old.actualizado_por,
|
||||
'OTRO'::public.tipo_cambio,
|
||||
'DELETE',
|
||||
to_jsonb(old),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return old;
|
||||
end if;
|
||||
|
||||
-- UPDATE ----------------------------------------------------------
|
||||
-- 1) Transición de estado
|
||||
if (new.estado_actual_id is distinct from old.estado_actual_id) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'TRANSICION_ESTADO'::public.tipo_cambio,
|
||||
'estado_actual_id',
|
||||
to_jsonb(old.estado_actual_id),
|
||||
to_jsonb(new.estado_actual_id),
|
||||
null
|
||||
);
|
||||
end if;
|
||||
|
||||
-- 2) Cambios en JSONB "datos" (diff top-level por llave)
|
||||
if (new.datos is distinct from old.datos) then
|
||||
for k in
|
||||
select distinct key
|
||||
from (
|
||||
select jsonb_object_keys(coalesce(old.datos, '{}'::jsonb)) as key
|
||||
union all
|
||||
select jsonb_object_keys(coalesce(new.datos, '{}'::jsonb)) as key
|
||||
) t
|
||||
loop
|
||||
old_val := coalesce(old.datos, '{}'::jsonb) -> k;
|
||||
new_val := coalesce(new.datos, '{}'::jsonb) -> k;
|
||||
|
||||
if (old_val is distinct from new_val) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'ACTUALIZACION_CAMPO'::public.tipo_cambio,
|
||||
k,
|
||||
old_val,
|
||||
new_val,
|
||||
v_response_id
|
||||
);
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
end if;
|
||||
|
||||
-- 3) Cambios en columnas "normales" (uno por columna)
|
||||
if (new.nombre is distinct from old.nombre) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nombre', to_jsonb(old.nombre), to_jsonb(new.nombre), null);
|
||||
end if;
|
||||
|
||||
if (new.nivel is distinct from old.nivel) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nivel', to_jsonb(old.nivel), to_jsonb(new.nivel), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_ciclo is distinct from old.tipo_ciclo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_ciclo', to_jsonb(old.tipo_ciclo), to_jsonb(new.tipo_ciclo), null);
|
||||
end if;
|
||||
|
||||
if (new.numero_ciclos is distinct from old.numero_ciclos) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'numero_ciclos', to_jsonb(old.numero_ciclos), to_jsonb(new.numero_ciclos), null);
|
||||
end if;
|
||||
|
||||
if (new.activo is distinct from old.activo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'activo', to_jsonb(old.activo), to_jsonb(new.activo), null);
|
||||
end if;
|
||||
|
||||
if (new.carrera_id is distinct from old.carrera_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'carrera_id', to_jsonb(old.carrera_id), to_jsonb(new.carrera_id), null);
|
||||
end if;
|
||||
|
||||
if (new.estructura_id is distinct from old.estructura_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'estructura_id', to_jsonb(old.estructura_id), to_jsonb(new.estructura_id), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_origen is distinct from old.tipo_origen) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_origen', to_jsonb(old.tipo_origen), to_jsonb(new.tipo_origen), null);
|
||||
end if;
|
||||
|
||||
|
||||
if (new.conversation_id is distinct from old.conversation_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'conversation_id', to_jsonb(old.conversation_id), to_jsonb(new.conversation_id), null);
|
||||
end if;
|
||||
|
||||
-- 🔥 consumirlo para que NO se guarde en planes_estudio
|
||||
if v_response_id is not null then
|
||||
new.meta_origen := new.meta_origen - 'response_id';
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;$function$
|
||||
;
|
||||
|
||||
CREATE TRIGGER "agregar-conversation_id-asignaturas" AFTER INSERT ON public.asignaturas FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/create-chat-conversation', 'POST', '{"Content-type":"application/json","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4ZGtzc3Vyem1qbm5oZ3RpYW1hIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MTM3ODYzMiwiZXhwIjoyMDU2OTU0NjMyfQ.s-GHuwnYbIYoMZN9dFbAKgxNyAtQllRCRPLy-GIRaro"}', '{}', '5000');
|
||||
|
||||
CREATE TRIGGER "agregar-conversation_id-planes_estudio" AFTER INSERT ON public.planes_estudio FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/create-chat-conversation', 'POST', '{"Content-type":"application/json","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4ZGtzc3Vyem1qbm5oZ3RpYW1hIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MTM3ODYzMiwiZXhwIjoyMDU2OTU0NjMyfQ.s-GHuwnYbIYoMZN9dFbAKgxNyAtQllRCRPLy-GIRaro"}', '{}', '5000');
|
||||
|
||||
CREATE TRIGGER trg_planes_estudio_log_cambios AFTER INSERT OR DELETE OR UPDATE ON public.planes_estudio FOR EACH ROW EXECUTE FUNCTION public.fn_log_cambios_planes_estudio();
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
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$
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
-- alter table "public"."asignaturas" drop constraint "asignaturas_facultad_propietaria_id_fkey";
|
||||
|
||||
-- alter table "public"."asignaturas" drop constraint "asignaturas_horas_semana_check";
|
||||
|
||||
-- alter table "public"."asignaturas" drop column "facultad_propietaria_id";
|
||||
|
||||
alter table "public"."asignaturas" drop column "horas_semana";
|
||||
|
||||
alter table "public"."asignaturas" add column "horas_academicas" integer;
|
||||
|
||||
alter table "public"."asignaturas" add column "horas_independientes" integer;
|
||||
|
||||
alter table "public"."asignaturas" add constraint "asignaturas_horas_academicas_check" CHECK (((horas_academicas IS NULL) OR (horas_academicas >= 0))) not valid;
|
||||
|
||||
alter table "public"."asignaturas" validate constraint "asignaturas_horas_academicas_check";
|
||||
|
||||
alter table "public"."asignaturas" add constraint "asignaturas_horas_independientes_check" CHECK (((horas_independientes IS NULL) OR (horas_independientes >= 0))) not valid;
|
||||
|
||||
alter table "public"."asignaturas" validate constraint "asignaturas_horas_independientes_check";
|
||||
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
create extension if not exists "http" with schema "extensions";
|
||||
|
||||
alter table "public"."asignaturas" drop constraint if exists "asignaturas_facultad_propietaria_id_fkey";
|
||||
|
||||
alter table "public"."cambios_plan" drop constraint "cambios_plan_plan_estudio_id_fkey";
|
||||
|
||||
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', 'ACTUALIZACION');
|
||||
|
||||
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";
|
||||
|
||||
alter table "public"."asignaturas" drop column if exists "facultad_propietaria_id";
|
||||
|
||||
alter table "public"."asignaturas" add column "asignatura_hash" text generated always as (encode(SUBSTRING(extensions.digest((id)::text, 'sha512'::text) FROM 1 FOR 12), 'hex'::text)) stored;
|
||||
|
||||
alter table "public"."cambios_plan" drop column "interaccion_ia_id";
|
||||
|
||||
alter table "public"."cambios_plan" add column "response_id" text;
|
||||
|
||||
alter table "public"."planes_estudio" add column "conversation_id" text;
|
||||
|
||||
alter table "public"."planes_estudio" add column "plan_hash" text generated always as (encode(SUBSTRING(extensions.digest((id)::text, 'sha512'::text) FROM 1 FOR 12), 'hex'::text)) stored;
|
||||
|
||||
CREATE UNIQUE INDEX planes_estudio_conversation_id_key ON public.planes_estudio USING btree (conversation_id);
|
||||
|
||||
alter table "public"."planes_estudio" add constraint "planes_estudio_conversation_id_key" UNIQUE using index "planes_estudio_conversation_id_key";
|
||||
|
||||
set check_function_bodies = off;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.fn_log_cambios_planes_estudio()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$declare
|
||||
k text;
|
||||
old_val jsonb;
|
||||
new_val jsonb;
|
||||
|
||||
v_response_id text;
|
||||
begin
|
||||
v_response_id := nullif(new.meta_origen->>'response_id','');
|
||||
|
||||
-- INSERT -> CREACION
|
||||
if tg_op = 'INSERT' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.creado_por,
|
||||
'CREACION'::public.tipo_cambio,
|
||||
null,
|
||||
null,
|
||||
to_jsonb(new),
|
||||
null
|
||||
);
|
||||
|
||||
return new;
|
||||
end if;
|
||||
|
||||
-- DELETE (opcional): si no lo quieres, bórralo
|
||||
if tg_op = 'DELETE' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
old.id,
|
||||
old.actualizado_por,
|
||||
'OTRO'::public.tipo_cambio,
|
||||
'DELETE',
|
||||
to_jsonb(old),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return old;
|
||||
end if;
|
||||
|
||||
-- UPDATE ----------------------------------------------------------
|
||||
-- 1) Transición de estado
|
||||
if (new.estado_actual_id is distinct from old.estado_actual_id) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'TRANSICION_ESTADO'::public.tipo_cambio,
|
||||
'estado_actual_id',
|
||||
to_jsonb(old.estado_actual_id),
|
||||
to_jsonb(new.estado_actual_id),
|
||||
null
|
||||
);
|
||||
end if;
|
||||
|
||||
-- 2) Cambios en JSONB "datos" (diff top-level por llave)
|
||||
if (new.datos is distinct from old.datos) then
|
||||
for k in
|
||||
select distinct key
|
||||
from (
|
||||
select jsonb_object_keys(coalesce(old.datos, '{}'::jsonb)) as key
|
||||
union all
|
||||
select jsonb_object_keys(coalesce(new.datos, '{}'::jsonb)) as key
|
||||
) t
|
||||
loop
|
||||
old_val := coalesce(old.datos, '{}'::jsonb) -> k;
|
||||
new_val := coalesce(new.datos, '{}'::jsonb) -> k;
|
||||
|
||||
if (old_val is distinct from new_val) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'ACTUALIZACION_CAMPO'::public.tipo_cambio,
|
||||
k,
|
||||
old_val,
|
||||
new_val,
|
||||
v_response_id
|
||||
);
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
end if;
|
||||
|
||||
-- 3) Cambios en columnas "normales" (uno por columna)
|
||||
if (new.nombre is distinct from old.nombre) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nombre', to_jsonb(old.nombre), to_jsonb(new.nombre), null);
|
||||
end if;
|
||||
|
||||
if (new.nivel is distinct from old.nivel) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nivel', to_jsonb(old.nivel), to_jsonb(new.nivel), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_ciclo is distinct from old.tipo_ciclo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_ciclo', to_jsonb(old.tipo_ciclo), to_jsonb(new.tipo_ciclo), null);
|
||||
end if;
|
||||
|
||||
if (new.numero_ciclos is distinct from old.numero_ciclos) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'numero_ciclos', to_jsonb(old.numero_ciclos), to_jsonb(new.numero_ciclos), null);
|
||||
end if;
|
||||
|
||||
if (new.activo is distinct from old.activo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'activo', to_jsonb(old.activo), to_jsonb(new.activo), null);
|
||||
end if;
|
||||
|
||||
if (new.carrera_id is distinct from old.carrera_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'carrera_id', to_jsonb(old.carrera_id), to_jsonb(new.carrera_id), null);
|
||||
end if;
|
||||
|
||||
if (new.estructura_id is distinct from old.estructura_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'estructura_id', to_jsonb(old.estructura_id), to_jsonb(new.estructura_id), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_origen is distinct from old.tipo_origen) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_origen', to_jsonb(old.tipo_origen), to_jsonb(new.tipo_origen), null);
|
||||
end if;
|
||||
|
||||
|
||||
if (new.conversation_id is distinct from old.conversation_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'conversation_id', to_jsonb(old.conversation_id), to_jsonb(new.conversation_id), null);
|
||||
end if;
|
||||
|
||||
-- 🔥 consumirlo para que NO se guarde en planes_estudio
|
||||
if v_response_id is not null then
|
||||
new.meta_origen := new.meta_origen - 'response_id';
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;$function$
|
||||
;
|
||||
|
||||
CREATE TRIGGER "agregar-conversation_id-asignaturas" AFTER INSERT ON public.asignaturas FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/create-chat-conversation', 'POST', '{"Content-type":"application/json","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4ZGtzc3Vyem1qbm5oZ3RpYW1hIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MTM3ODYzMiwiZXhwIjoyMDU2OTU0NjMyfQ.s-GHuwnYbIYoMZN9dFbAKgxNyAtQllRCRPLy-GIRaro"}', '{}', '5000');
|
||||
|
||||
CREATE TRIGGER "agregar-conversation_id-planes_estudio" AFTER INSERT ON public.planes_estudio FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/create-chat-conversation', 'POST', '{"Content-type":"application/json","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4ZGtzc3Vyem1qbm5oZ3RpYW1hIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MTM3ODYzMiwiZXhwIjoyMDU2OTU0NjMyfQ.s-GHuwnYbIYoMZN9dFbAKgxNyAtQllRCRPLy-GIRaro"}', '{}', '5000');
|
||||
|
||||
CREATE TRIGGER trg_planes_estudio_log_cambios AFTER INSERT OR DELETE OR UPDATE ON public.planes_estudio FOR EACH ROW EXECUTE FUNCTION public.fn_log_cambios_planes_estudio();
|
||||
|
||||
|
||||
+260
-14
@@ -30,6 +30,13 @@ COMMENT ON SCHEMA "public" IS 'standard public schema';
|
||||
|
||||
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS "http" WITH SCHEMA "extensions";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS "pg_graphql" WITH SCHEMA "graphql";
|
||||
|
||||
|
||||
@@ -159,7 +166,8 @@ CREATE TYPE "public"."tipo_cambio" AS ENUM (
|
||||
'ACTUALIZACION_MAPA',
|
||||
'TRANSICION_ESTADO',
|
||||
'OTRO',
|
||||
'CREACION'
|
||||
'CREACION',
|
||||
'ACTUALIZACION'
|
||||
);
|
||||
|
||||
|
||||
@@ -230,6 +238,172 @@ CREATE TYPE "public"."tipo_origen" AS ENUM (
|
||||
ALTER TYPE "public"."tipo_origen" OWNER TO "postgres";
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION "public"."fn_log_cambios_planes_estudio"() RETURNS "trigger"
|
||||
LANGUAGE "plpgsql"
|
||||
AS $$declare
|
||||
k text;
|
||||
old_val jsonb;
|
||||
new_val jsonb;
|
||||
|
||||
v_response_id text;
|
||||
begin
|
||||
v_response_id := nullif(new.meta_origen->>'response_id','');
|
||||
|
||||
-- INSERT -> CREACION
|
||||
if tg_op = 'INSERT' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.creado_por,
|
||||
'CREACION'::public.tipo_cambio,
|
||||
null,
|
||||
null,
|
||||
to_jsonb(new),
|
||||
null
|
||||
);
|
||||
|
||||
return new;
|
||||
end if;
|
||||
|
||||
-- DELETE (opcional): si no lo quieres, bórralo
|
||||
if tg_op = 'DELETE' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
old.id,
|
||||
old.actualizado_por,
|
||||
'OTRO'::public.tipo_cambio,
|
||||
'DELETE',
|
||||
to_jsonb(old),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return old;
|
||||
end if;
|
||||
|
||||
-- UPDATE ----------------------------------------------------------
|
||||
-- 1) Transición de estado
|
||||
if (new.estado_actual_id is distinct from old.estado_actual_id) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'TRANSICION_ESTADO'::public.tipo_cambio,
|
||||
'estado_actual_id',
|
||||
to_jsonb(old.estado_actual_id),
|
||||
to_jsonb(new.estado_actual_id),
|
||||
null
|
||||
);
|
||||
end if;
|
||||
|
||||
-- 2) Cambios en JSONB "datos" (diff top-level por llave)
|
||||
if (new.datos is distinct from old.datos) then
|
||||
for k in
|
||||
select distinct key
|
||||
from (
|
||||
select jsonb_object_keys(coalesce(old.datos, '{}'::jsonb)) as key
|
||||
union all
|
||||
select jsonb_object_keys(coalesce(new.datos, '{}'::jsonb)) as key
|
||||
) t
|
||||
loop
|
||||
old_val := coalesce(old.datos, '{}'::jsonb) -> k;
|
||||
new_val := coalesce(new.datos, '{}'::jsonb) -> k;
|
||||
|
||||
if (old_val is distinct from new_val) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'ACTUALIZACION_CAMPO'::public.tipo_cambio,
|
||||
k,
|
||||
old_val,
|
||||
new_val,
|
||||
v_response_id
|
||||
);
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
end if;
|
||||
|
||||
-- 3) Cambios en columnas "normales" (uno por columna)
|
||||
if (new.nombre is distinct from old.nombre) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nombre', to_jsonb(old.nombre), to_jsonb(new.nombre), null);
|
||||
end if;
|
||||
|
||||
if (new.nivel is distinct from old.nivel) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nivel', to_jsonb(old.nivel), to_jsonb(new.nivel), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_ciclo is distinct from old.tipo_ciclo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_ciclo', to_jsonb(old.tipo_ciclo), to_jsonb(new.tipo_ciclo), null);
|
||||
end if;
|
||||
|
||||
if (new.numero_ciclos is distinct from old.numero_ciclos) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'numero_ciclos', to_jsonb(old.numero_ciclos), to_jsonb(new.numero_ciclos), null);
|
||||
end if;
|
||||
|
||||
if (new.activo is distinct from old.activo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'activo', to_jsonb(old.activo), to_jsonb(new.activo), null);
|
||||
end if;
|
||||
|
||||
if (new.carrera_id is distinct from old.carrera_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'carrera_id', to_jsonb(old.carrera_id), to_jsonb(new.carrera_id), null);
|
||||
end if;
|
||||
|
||||
if (new.estructura_id is distinct from old.estructura_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'estructura_id', to_jsonb(old.estructura_id), to_jsonb(new.estructura_id), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_origen is distinct from old.tipo_origen) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_origen', to_jsonb(old.tipo_origen), to_jsonb(new.tipo_origen), null);
|
||||
end if;
|
||||
|
||||
|
||||
if (new.conversation_id is distinct from old.conversation_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'conversation_id', to_jsonb(old.conversation_id), to_jsonb(new.conversation_id), null);
|
||||
end if;
|
||||
|
||||
-- 🔥 consumirlo para que NO se guarde en planes_estudio
|
||||
if v_response_id is not null then
|
||||
new.meta_origen := new.meta_origen - 'response_id';
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;$$;
|
||||
|
||||
|
||||
ALTER FUNCTION "public"."fn_log_cambios_planes_estudio"() OWNER TO "postgres";
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION "public"."set_actualizado_en"() RETURNS "trigger"
|
||||
LANGUAGE "plpgsql"
|
||||
AS $$
|
||||
@@ -246,7 +420,7 @@ ALTER FUNCTION "public"."set_actualizado_en"() OWNER TO "postgres";
|
||||
CREATE OR REPLACE FUNCTION "public"."unaccent_immutable"("text") RETURNS "text"
|
||||
LANGUAGE "sql" IMMUTABLE STRICT PARALLEL SAFE
|
||||
AS $_$
|
||||
SELECT unaccent('unaccent', $1);
|
||||
SELECT public.unaccent('public.unaccent', $1);
|
||||
$_$;
|
||||
|
||||
|
||||
@@ -313,7 +487,6 @@ CREATE TABLE IF NOT EXISTS "public"."asignaturas" (
|
||||
"id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
|
||||
"plan_estudio_id" "uuid" NOT NULL,
|
||||
"estructura_id" "uuid",
|
||||
"facultad_propietaria_id" "uuid",
|
||||
"codigo" "text",
|
||||
"nombre" "text" NOT NULL,
|
||||
"tipo" "public"."tipo_asignatura" DEFAULT 'OBLIGATORIA'::"public"."tipo_asignatura" NOT NULL,
|
||||
@@ -330,6 +503,7 @@ CREATE TABLE IF NOT EXISTS "public"."asignaturas" (
|
||||
"actualizado_por" "uuid",
|
||||
"creado_en" timestamp with time zone DEFAULT "now"() NOT NULL,
|
||||
"actualizado_en" timestamp with time zone DEFAULT "now"() NOT NULL,
|
||||
"asignatura_hash" "text" GENERATED ALWAYS AS ("encode"(SUBSTRING("extensions"."digest"(("id")::"text", 'sha512'::"text") FROM 1 FOR 12), 'hex'::"text")) STORED,
|
||||
CONSTRAINT "asignaturas_ciclo_chk" CHECK ((("numero_ciclo" IS NULL) OR ("numero_ciclo" > 0))),
|
||||
CONSTRAINT "asignaturas_creditos_check" CHECK (("creditos" >= (0)::numeric)),
|
||||
CONSTRAINT "asignaturas_horas_semana_check" CHECK ((("horas_semana" IS NULL) OR ("horas_semana" >= 0))),
|
||||
@@ -382,13 +556,17 @@ CREATE TABLE IF NOT EXISTS "public"."cambios_plan" (
|
||||
"campo" "text",
|
||||
"valor_anterior" "jsonb",
|
||||
"valor_nuevo" "jsonb",
|
||||
"interaccion_ia_id" "uuid"
|
||||
"response_id" "text"
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE "public"."cambios_plan" OWNER TO "postgres";
|
||||
|
||||
|
||||
COMMENT ON COLUMN "public"."cambios_plan"."response_id" IS 'El ID de respuesta de OpenAI';
|
||||
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "public"."carreras" (
|
||||
"id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL,
|
||||
"facultad_id" "uuid" NOT NULL,
|
||||
@@ -525,6 +703,8 @@ CREATE TABLE IF NOT EXISTS "public"."planes_estudio" (
|
||||
"creado_en" timestamp with time zone DEFAULT "now"() NOT NULL,
|
||||
"actualizado_en" timestamp with time zone DEFAULT "now"() NOT NULL,
|
||||
"nombre_search" "text" GENERATED ALWAYS AS ("lower"("public"."unaccent_immutable"("nombre"))) STORED,
|
||||
"plan_hash" "text" GENERATED ALWAYS AS ("encode"(SUBSTRING("extensions"."digest"(("id")::"text", 'sha512'::"text") FROM 1 FOR 12), 'hex'::"text")) STORED,
|
||||
"conversation_id" "text",
|
||||
CONSTRAINT "planes_estudio_numero_ciclos_check" CHECK (("numero_ciclos" > 0))
|
||||
);
|
||||
|
||||
@@ -532,6 +712,10 @@ CREATE TABLE IF NOT EXISTS "public"."planes_estudio" (
|
||||
ALTER TABLE "public"."planes_estudio" OWNER TO "postgres";
|
||||
|
||||
|
||||
COMMENT ON COLUMN "public"."planes_estudio"."conversation_id" IS 'ID de conversación de OpenAI';
|
||||
|
||||
|
||||
|
||||
CREATE OR REPLACE VIEW "public"."plantilla_plan" AS
|
||||
SELECT "plan"."id" AS "plan_estudio_id",
|
||||
"struct"."id" AS "estructura_id",
|
||||
@@ -714,6 +898,11 @@ ALTER TABLE ONLY "public"."notificaciones"
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY "public"."planes_estudio"
|
||||
ADD CONSTRAINT "planes_estudio_conversation_id_key" UNIQUE ("conversation_id");
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY "public"."planes_estudio"
|
||||
ADD CONSTRAINT "planes_estudio_pkey" PRIMARY KEY ("id");
|
||||
|
||||
@@ -826,6 +1015,10 @@ CREATE OR REPLACE TRIGGER "trg_planes_estudio_actualizado_en" BEFORE UPDATE ON "
|
||||
|
||||
|
||||
|
||||
CREATE OR REPLACE TRIGGER "trg_planes_estudio_log_cambios" AFTER INSERT OR DELETE OR UPDATE ON "public"."planes_estudio" FOR EACH ROW EXECUTE FUNCTION "public"."fn_log_cambios_planes_estudio"();
|
||||
|
||||
|
||||
|
||||
CREATE OR REPLACE TRIGGER "trg_usuarios_app_actualizado_en" BEFORE UPDATE ON "public"."usuarios_app" FOR EACH ROW EXECUTE FUNCTION "public"."set_actualizado_en"();
|
||||
|
||||
|
||||
@@ -854,11 +1047,6 @@ ALTER TABLE ONLY "public"."asignaturas"
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY "public"."asignaturas"
|
||||
ADD CONSTRAINT "asignaturas_facultad_propietaria_id_fkey" FOREIGN KEY ("facultad_propietaria_id") REFERENCES "public"."facultades"("id") ON DELETE SET NULL;
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY "public"."asignaturas"
|
||||
ADD CONSTRAINT "asignaturas_linea_plan_fk_compuesta" FOREIGN KEY ("linea_plan_id", "plan_estudio_id") REFERENCES "public"."lineas_plan"("id", "plan_estudio_id") ON DELETE SET NULL;
|
||||
|
||||
@@ -894,11 +1082,6 @@ ALTER TABLE ONLY "public"."cambios_plan"
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY "public"."cambios_plan"
|
||||
ADD CONSTRAINT "cambios_plan_plan_estudio_id_fkey" FOREIGN KEY ("plan_estudio_id") REFERENCES "public"."planes_estudio"("id") ON DELETE CASCADE;
|
||||
|
||||
|
||||
|
||||
ALTER TABLE ONLY "public"."carreras"
|
||||
ADD CONSTRAINT "carreras_facultad_id_fkey" FOREIGN KEY ("facultad_id") REFERENCES "public"."facultades"("id") ON DELETE RESTRICT;
|
||||
|
||||
@@ -1220,6 +1403,69 @@ GRANT USAGE ON SCHEMA "public" TO "service_role";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
GRANT ALL ON FUNCTION "public"."fn_log_cambios_planes_estudio"() TO "anon";
|
||||
GRANT ALL ON FUNCTION "public"."fn_log_cambios_planes_estudio"() TO "authenticated";
|
||||
GRANT ALL ON FUNCTION "public"."fn_log_cambios_planes_estudio"() TO "service_role";
|
||||
|
||||
|
||||
|
||||
GRANT ALL ON FUNCTION "public"."set_actualizado_en"() TO "anon";
|
||||
GRANT ALL ON FUNCTION "public"."set_actualizado_en"() TO "authenticated";
|
||||
GRANT ALL ON FUNCTION "public"."set_actualizado_en"() TO "service_role";
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
create extension if not exists "http" with schema "extensions";
|
||||
|
||||
alter table "public"."asignaturas" drop constraint if exists "asignaturas_facultad_propietaria_id_fkey";
|
||||
|
||||
alter table "public"."cambios_plan" drop constraint "cambios_plan_plan_estudio_id_fkey";
|
||||
|
||||
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', 'ACTUALIZACION');
|
||||
|
||||
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";
|
||||
|
||||
alter table "public"."asignaturas" drop column if exists "facultad_propietaria_id";
|
||||
|
||||
alter table "public"."asignaturas" add column "asignatura_hash" text generated always as (encode(SUBSTRING(extensions.digest((id)::text, 'sha512'::text) FROM 1 FOR 12), 'hex'::text)) stored;
|
||||
|
||||
alter table "public"."cambios_plan" drop column "interaccion_ia_id";
|
||||
|
||||
alter table "public"."cambios_plan" add column "response_id" text;
|
||||
|
||||
alter table "public"."planes_estudio" add column "conversation_id" text;
|
||||
|
||||
alter table "public"."planes_estudio" add column "plan_hash" text generated always as (encode(SUBSTRING(extensions.digest((id)::text, 'sha512'::text) FROM 1 FOR 12), 'hex'::text)) stored;
|
||||
|
||||
CREATE UNIQUE INDEX planes_estudio_conversation_id_key ON public.planes_estudio USING btree (conversation_id);
|
||||
|
||||
alter table "public"."planes_estudio" add constraint "planes_estudio_conversation_id_key" UNIQUE using index "planes_estudio_conversation_id_key";
|
||||
|
||||
set check_function_bodies = off;
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.fn_log_cambios_planes_estudio()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $function$declare
|
||||
k text;
|
||||
old_val jsonb;
|
||||
new_val jsonb;
|
||||
|
||||
v_response_id text;
|
||||
begin
|
||||
v_response_id := nullif(new.meta_origen->>'response_id','');
|
||||
|
||||
-- INSERT -> CREACION
|
||||
if tg_op = 'INSERT' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.creado_por,
|
||||
'CREACION'::public.tipo_cambio,
|
||||
null,
|
||||
null,
|
||||
to_jsonb(new),
|
||||
null
|
||||
);
|
||||
|
||||
return new;
|
||||
end if;
|
||||
|
||||
-- DELETE (opcional): si no lo quieres, bórralo
|
||||
if tg_op = 'DELETE' then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id,
|
||||
cambiado_por,
|
||||
tipo,
|
||||
campo,
|
||||
valor_anterior,
|
||||
valor_nuevo,
|
||||
response_id
|
||||
)
|
||||
values (
|
||||
old.id,
|
||||
old.actualizado_por,
|
||||
'OTRO'::public.tipo_cambio,
|
||||
'DELETE',
|
||||
to_jsonb(old),
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return old;
|
||||
end if;
|
||||
|
||||
-- UPDATE ----------------------------------------------------------
|
||||
-- 1) Transición de estado
|
||||
if (new.estado_actual_id is distinct from old.estado_actual_id) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'TRANSICION_ESTADO'::public.tipo_cambio,
|
||||
'estado_actual_id',
|
||||
to_jsonb(old.estado_actual_id),
|
||||
to_jsonb(new.estado_actual_id),
|
||||
null
|
||||
);
|
||||
end if;
|
||||
|
||||
-- 2) Cambios en JSONB "datos" (diff top-level por llave)
|
||||
if (new.datos is distinct from old.datos) then
|
||||
for k in
|
||||
select distinct key
|
||||
from (
|
||||
select jsonb_object_keys(coalesce(old.datos, '{}'::jsonb)) as key
|
||||
union all
|
||||
select jsonb_object_keys(coalesce(new.datos, '{}'::jsonb)) as key
|
||||
) t
|
||||
loop
|
||||
old_val := coalesce(old.datos, '{}'::jsonb) -> k;
|
||||
new_val := coalesce(new.datos, '{}'::jsonb) -> k;
|
||||
|
||||
if (old_val is distinct from new_val) then
|
||||
insert into public.cambios_plan (
|
||||
plan_estudio_id, cambiado_por, tipo, campo, valor_anterior, valor_nuevo, response_id
|
||||
)
|
||||
values (
|
||||
new.id,
|
||||
new.actualizado_por,
|
||||
'ACTUALIZACION_CAMPO'::public.tipo_cambio,
|
||||
k,
|
||||
old_val,
|
||||
new_val,
|
||||
v_response_id
|
||||
);
|
||||
end if;
|
||||
end loop;
|
||||
|
||||
end if;
|
||||
|
||||
-- 3) Cambios en columnas "normales" (uno por columna)
|
||||
if (new.nombre is distinct from old.nombre) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nombre', to_jsonb(old.nombre), to_jsonb(new.nombre), null);
|
||||
end if;
|
||||
|
||||
if (new.nivel is distinct from old.nivel) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'nivel', to_jsonb(old.nivel), to_jsonb(new.nivel), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_ciclo is distinct from old.tipo_ciclo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_ciclo', to_jsonb(old.tipo_ciclo), to_jsonb(new.tipo_ciclo), null);
|
||||
end if;
|
||||
|
||||
if (new.numero_ciclos is distinct from old.numero_ciclos) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'numero_ciclos', to_jsonb(old.numero_ciclos), to_jsonb(new.numero_ciclos), null);
|
||||
end if;
|
||||
|
||||
if (new.activo is distinct from old.activo) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'activo', to_jsonb(old.activo), to_jsonb(new.activo), null);
|
||||
end if;
|
||||
|
||||
if (new.carrera_id is distinct from old.carrera_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'carrera_id', to_jsonb(old.carrera_id), to_jsonb(new.carrera_id), null);
|
||||
end if;
|
||||
|
||||
if (new.estructura_id is distinct from old.estructura_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'estructura_id', to_jsonb(old.estructura_id), to_jsonb(new.estructura_id), null);
|
||||
end if;
|
||||
|
||||
if (new.tipo_origen is distinct from old.tipo_origen) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'tipo_origen', to_jsonb(old.tipo_origen), to_jsonb(new.tipo_origen), null);
|
||||
end if;
|
||||
|
||||
|
||||
if (new.conversation_id is distinct from old.conversation_id) then
|
||||
insert into public.cambios_plan values (gen_random_uuid(), new.id, new.actualizado_por, now(),
|
||||
'ACTUALIZACION'::public.tipo_cambio, 'conversation_id', to_jsonb(old.conversation_id), to_jsonb(new.conversation_id), null);
|
||||
end if;
|
||||
|
||||
-- 🔥 consumirlo para que NO se guarde en planes_estudio
|
||||
if v_response_id is not null then
|
||||
new.meta_origen := new.meta_origen - 'response_id';
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;$function$
|
||||
;
|
||||
|
||||
CREATE TRIGGER "agregar-conversation_id-asignaturas" AFTER INSERT ON public.asignaturas FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/create-chat-conversation', 'POST', '{"Content-type":"application/json","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4ZGtzc3Vyem1qbm5oZ3RpYW1hIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MTM3ODYzMiwiZXhwIjoyMDU2OTU0NjMyfQ.s-GHuwnYbIYoMZN9dFbAKgxNyAtQllRCRPLy-GIRaro"}', '{}', '5000');
|
||||
|
||||
CREATE TRIGGER "agregar-conversation_id-planes_estudio" AFTER INSERT ON public.planes_estudio FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://exdkssurzmjnnhgtiama.supabase.co/functions/v1/create-chat-conversation', 'POST', '{"Content-type":"application/json","Authorization":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV4ZGtzc3Vyem1qbm5oZ3RpYW1hIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MTM3ODYzMiwiZXhwIjoyMDU2OTU0NjMyfQ.s-GHuwnYbIYoMZN9dFbAKgxNyAtQllRCRPLy-GIRaro"}', '{}', '5000');
|
||||
|
||||
CREATE TRIGGER trg_planes_estudio_log_cambios AFTER INSERT OR DELETE OR UPDATE ON public.planes_estudio FOR EACH ROW EXECUTE FUNCTION public.fn_log_cambios_planes_estudio();
|
||||
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
INSERT INTO public.facultades (nombre, nombre_corto, color, icono) VALUES
|
||||
--('Otros', 'OTRO', '#64748B', 'MoreHorizontal'),
|
||||
('Coordinación de Desarrollo Humano Profesional', 'CDHP', '#F472B6', 'HeartHandshake'),
|
||||
('Centro de Idiomas', 'CI', '#2DD4BF', 'Languages'),
|
||||
--('Campus Virtual La Salle', 'CVLS', '#8B5CF6', 'Monitor'),
|
||||
('Escuela de Altos Estudios en Salud', 'EAES', '#F43F5E', 'Stethoscope'),
|
||||
--('Escuela Preparatoria Unidad Santa Teresa', 'EPST', '#EAB308', 'Backpack'),
|
||||
--('Escuela Preparatoria Unidad Condesa', 'EPUC', '#F59E0B', 'BookOpen'),
|
||||
('Facultad Mexicana de Arquitectura, Diseño y Comunicación', 'FAMADYC', '#EC4899', 'DraftingCompass'),
|
||||
--('Facultad de Negocios', 'NEG', '#3B82F6', 'Briefcase'),
|
||||
('Facultad de Derecho', 'DER', '#64748B', 'Scale'),
|
||||
('Facultad de Humanidades y Ciencias Sociales', 'HUM', '#6366F1', 'Users'),
|
||||
--('Facultad de Ingeniería', 'ING', '#F97316', 'Cpu'),
|
||||
('Facultad Mexicana de Medicina', 'MED', '#10B981', 'HeartPulse'),
|
||||
('Facultad de Ciencias Químicas', 'FCQ', '#84CC16', 'FlaskConical'),
|
||||
('Escuela de Ciencias Religiosas', 'ECR', '#0EA5E9', 'BookHeart'),
|
||||
('Escuela de Ciencias de la Educación', 'EDU', '#FB7185', 'GraduationCap');
|
||||
--('Dirección Campus Virtual', 'DCV', '#A855F7', 'Globe');
|
||||
|
||||
INSERT INTO public.carreras (facultad_id, nombre, nombre_corto) VALUES
|
||||
-- Coordinación de Desarrollo Humano Profesional
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Coordinación de Desarrollo Humano Profesional' LIMIT 1), 'Área Curricular Común 2013', 'ACC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Coordinación de Desarrollo Humano Profesional' LIMIT 1), 'Área Curricular Común 2021', 'ACC'),
|
||||
|
||||
-- Centro de Idiomas
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Centro de Idiomas' LIMIT 1), 'Área Curricular Común (Centro de Idiomas) 2013', 'ACCI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Centro de Idiomas' LIMIT 1), 'Área Curricular Común (Centro de Idiomas) 2021', 'ACCI'),
|
||||
|
||||
-- Escuela de Altos Estudios en Salud
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Escuela de Altos Estudios en Salud' LIMIT 1), 'Licenciatura en Enfermería', 'LENF'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Escuela de Altos Estudios en Salud' LIMIT 1), 'Licenciatura en Fisioterapia y Promoción para la Salud', 'LFPS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Escuela de Altos Estudios en Salud' LIMIT 1), 'Licenciatura en Ciencias en el Deporte', 'LCD'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Escuela de Altos Estudios en Salud' LIMIT 1), 'Licenciatura en Medicina Dental', 'LMD'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Escuela de Altos Estudios en Salud' LIMIT 1), 'Maestría en Nutrición Clínica', 'MNC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Escuela de Altos Estudios en Salud' LIMIT 1), 'Licenciatura en Fisioterapia', 'LFIS'),
|
||||
|
||||
-- Facultad Mexicana de Arquitectura, Diseño y Comunicación
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Licenciatura en Arquitectura', 'ARQ'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Licenciatura en Ciencias de la Comunicación', 'LCC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Licenciatura en Diseño Gráfico y Digital', 'LDGD'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Licenciatura en Diseño de Ambientes Interiores y Exteriores', 'LDAI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Especialidad en Gestión y Administración de Proyectos', 'EGAP'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Maestría en Estrategia e Innovación en Marcas', 'MEIM'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Maestría en Dirección Estratégica de Comunicación', 'MDEC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Licenciatura en Comunicación', 'LCOM'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Licenciatura en Diseño de Productos', 'LDP'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Arquitectura, Diseño y Comunicación' LIMIT 1), 'Especialidad en Dirección de Proyectos', 'EDP'),
|
||||
|
||||
-- Facultad de Derecho
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Licenciatura en Derecho', 'LDER'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Licenciatura en Relaciones Internacionales', 'LRI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Maestría en Derecho Financiero', 'MDF'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Especialidad en Derecho de Empresa', 'EDE'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Maestría en Gobernanza y Estrategia Internacional', 'MGEI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Doctorado en Ciencias Jurídicas', 'DCJ'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Maestría en Derecho Civil', 'MDC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Maestría en Derecho de Empresa', 'MDE'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Derecho' LIMIT 1), 'Maestría en Justicia Penal', 'MJP'),
|
||||
|
||||
-- Facultad de Humanidades y Ciencias Sociales
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Educación Preescolar', 'LEP'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Ciencias Religiosas', 'LCR'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Filosofía', 'LFIL'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Maestría en Filosofía Social', 'MFS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Área de Gestión Educativa', 'AGE'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Área de Intervención Docente', 'AID'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Especialidad en Gestión de los Aprendizajes', 'EGA'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Doctorado en Educación', 'DOCE'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Psicología', 'LPS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Educación Primaria', 'LEPR'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Ciencias de la Educación', 'LCE'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Pedagogía', 'LPED'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Humanidades y Ciencias Sociales' LIMIT 1), 'Licenciatura en Teología', 'LTEO'),
|
||||
|
||||
-- Facultad Mexicana de Medicina
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad Mexicana de Medicina' LIMIT 1), 'Licenciatura en Médico Cirujano', 'LMC'),
|
||||
|
||||
-- Facultad de Ciencias Químicas
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Licenciatura en Ingeniería Química', 'LIQ'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Licenciatura en Químico Farmacéutico Biólogo', 'QFB'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Licenciatura en Química de Alimentos', 'LQA'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Licenciatura en Ingeniería Ambiental', 'LIA'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Maestría en Ciencia de los Alimentos y Nutrición Humana', 'MCAN'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Maestría en Farmacología Clínica', 'MFC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Maestría en Calidad y Estadística Aplicada', 'MCEA'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ciencias Químicas' LIMIT 1), 'Maestría en Ingeniería de Proyectos', 'MIP'),
|
||||
|
||||
-- Facultad de Negocios
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Contaduría y Finanzas', 'LCF'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Mercadotecnia', 'LMER'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Comercio y Negocios Internacionales', 'LCNI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Administración', 'LADM'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Tecnologías de Información', 'LTI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Dirección de Organizaciones de la Salud', 'MDOS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Actuaría', 'LACT'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Especialidad en Mercadotecnia y Publicidad', 'EMP'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Especialidad en Finanzas Corporativas y Bursátiles', 'EFCB'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Especialidad en Logística y Cadena de Suministro', 'ELCS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Especialidad en Administración de Organizaciones de la Salud', 'EAOS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Ciencias Actuariales', 'MCA'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Doctorado en Administración', 'DADM'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Administración de Organizaciones de la Salud', 'MAOS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Administración de Negocios Internacionales', 'MANI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Tecnologías de Información en la Dirección de Negocios', 'MTID'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Administración', 'MADM'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Ingeniería Económica y Financiera', 'MIEF'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Administración de Negocios Internacionales (MIEX)', 'MIEX'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Maestría en Gestión Estratégica del Capital Humano', 'MGEC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Administración e Innovación de Negocios', 'LAIN'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Ingeniería Económica y Financiera', 'LIEF'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Negocios' LIMIT 1), 'Licenciatura en Transformación Digital para los Negocios', 'LTDN'),
|
||||
|
||||
-- Facultad de Ingeniería
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Electrónica', 'LIE'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Civil', 'LIC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Mecánica y en Sistemas Energéticos', 'LIME'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Electrónica para Sistemas Inteligentes', 'LIES'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Mecatrónica', 'LIM'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Industrial', 'LII'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Cibernética y Sistemas Computacionales', 'LICS'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Licenciatura en Ingeniería Biomédica', 'LIB'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Maestría en Gerencia de Proyectos Inmobiliarios', 'MGPI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Maestría en Dirección Industrial', 'MDI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Especialidad en Dirección Industrial', 'EDI'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Maestría en Gestión de Proyectos y de Empresas Constructoras', 'MGPC'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Especialidad en Energías Renovables', 'EER'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Maestría en Ciberseguridad', 'MCIB'),
|
||||
((SELECT id FROM public.facultades WHERE nombre = 'Facultad de Ingeniería' LIMIT 1), 'Especialidad en Inteligencia de Datos', 'EID');
|
||||
Reference in New Issue
Block a user