209 lines
9.0 KiB
SQL
209 lines
9.0 KiB
SQL
create type "public"."estado_conversacion" as enum ('ACTIVA', 'ARCHIVANDO', 'ARCHIVADA', 'ERROR');
|
|
|
|
alter table "public"."planes_estudio" drop constraint "planes_estudio_conversation_id_key";
|
|
|
|
drop view if exists "public"."plantilla_plan";
|
|
|
|
drop index if exists "public"."planes_estudio_conversation_id_key";
|
|
|
|
|
|
create table "public"."conversaciones_asignatura" (
|
|
"id" uuid not null default gen_random_uuid(),
|
|
"asignatura_id" uuid not null,
|
|
"openai_conversation_id" text not null,
|
|
"estado" public.estado_conversacion not null default 'ACTIVA'::public.estado_conversacion,
|
|
"conversacion_json" jsonb not null default '{}'::jsonb,
|
|
"creado_por" uuid,
|
|
"creado_en" timestamp with time zone not null default now(),
|
|
"archivado_por" uuid,
|
|
"archivado_en" timestamp with time zone,
|
|
"intento_archivado" integer not null default 0
|
|
);
|
|
|
|
|
|
|
|
create table "public"."conversaciones_plan" (
|
|
"id" uuid not null default gen_random_uuid(),
|
|
"plan_estudio_id" uuid not null,
|
|
"openai_conversation_id" text not null,
|
|
"estado" public.estado_conversacion not null default 'ACTIVA'::public.estado_conversacion,
|
|
"conversacion_json" jsonb not null default '{}'::jsonb,
|
|
"creado_por" uuid,
|
|
"creado_en" timestamp with time zone not null default now(),
|
|
"archivado_por" uuid,
|
|
"archivado_en" timestamp with time zone,
|
|
"intento_archivado" integer not null default 0
|
|
);
|
|
|
|
|
|
alter table "public"."planes_estudio" drop column "conversation_id";
|
|
|
|
CREATE UNIQUE INDEX conversaciones_asignatura_openai_id_unico ON public.conversaciones_asignatura USING btree (openai_conversation_id);
|
|
|
|
CREATE UNIQUE INDEX conversaciones_asignatura_pkey ON public.conversaciones_asignatura USING btree (id);
|
|
|
|
CREATE UNIQUE INDEX conversaciones_plan_openai_id_unico ON public.conversaciones_plan USING btree (openai_conversation_id);
|
|
|
|
CREATE UNIQUE INDEX conversaciones_plan_pkey ON public.conversaciones_plan USING btree (id);
|
|
|
|
CREATE INDEX idx_conv_asig_asignatura ON public.conversaciones_asignatura USING btree (asignatura_id);
|
|
|
|
CREATE INDEX idx_conv_asig_estado ON public.conversaciones_asignatura USING btree (estado);
|
|
|
|
CREATE INDEX idx_conv_plan_estado ON public.conversaciones_plan USING btree (estado);
|
|
|
|
CREATE INDEX idx_conv_plan_plan_estudio ON public.conversaciones_plan USING btree (plan_estudio_id);
|
|
|
|
alter table "public"."conversaciones_asignatura" add constraint "conversaciones_asignatura_pkey" PRIMARY KEY using index "conversaciones_asignatura_pkey";
|
|
|
|
alter table "public"."conversaciones_plan" add constraint "conversaciones_plan_pkey" PRIMARY KEY using index "conversaciones_plan_pkey";
|
|
|
|
alter table "public"."conversaciones_asignatura" add constraint "conversaciones_asignatura_archivado_por_fkey" FOREIGN KEY (archivado_por) REFERENCES public.usuarios_app(id) ON DELETE SET NULL not valid;
|
|
|
|
alter table "public"."conversaciones_asignatura" validate constraint "conversaciones_asignatura_archivado_por_fkey";
|
|
|
|
alter table "public"."conversaciones_asignatura" add constraint "conversaciones_asignatura_asignatura_id_fkey" FOREIGN KEY (asignatura_id) REFERENCES public.asignaturas(id) ON DELETE CASCADE not valid;
|
|
|
|
alter table "public"."conversaciones_asignatura" validate constraint "conversaciones_asignatura_asignatura_id_fkey";
|
|
|
|
alter table "public"."conversaciones_asignatura" add constraint "conversaciones_asignatura_creado_por_fkey" FOREIGN KEY (creado_por) REFERENCES public.usuarios_app(id) ON DELETE SET NULL not valid;
|
|
|
|
alter table "public"."conversaciones_asignatura" validate constraint "conversaciones_asignatura_creado_por_fkey";
|
|
|
|
alter table "public"."conversaciones_asignatura" add constraint "conversaciones_asignatura_openai_id_unico" UNIQUE using index "conversaciones_asignatura_openai_id_unico";
|
|
|
|
alter table "public"."conversaciones_plan" add constraint "conversaciones_plan_archivado_por_fkey" FOREIGN KEY (archivado_por) REFERENCES public.usuarios_app(id) ON DELETE SET NULL not valid;
|
|
|
|
alter table "public"."conversaciones_plan" validate constraint "conversaciones_plan_archivado_por_fkey";
|
|
|
|
alter table "public"."conversaciones_plan" add constraint "conversaciones_plan_creado_por_fkey" FOREIGN KEY (creado_por) REFERENCES public.usuarios_app(id) ON DELETE SET NULL not valid;
|
|
|
|
alter table "public"."conversaciones_plan" validate constraint "conversaciones_plan_creado_por_fkey";
|
|
|
|
alter table "public"."conversaciones_plan" add constraint "conversaciones_plan_openai_id_unico" UNIQUE using index "conversaciones_plan_openai_id_unico";
|
|
|
|
alter table "public"."conversaciones_plan" add constraint "conversaciones_plan_plan_estudio_id_fkey" FOREIGN KEY (plan_estudio_id) REFERENCES public.planes_estudio(id) ON DELETE CASCADE not valid;
|
|
|
|
alter table "public"."conversaciones_plan" validate constraint "conversaciones_plan_plan_estudio_id_fkey";
|
|
|
|
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)));
|
|
|
|
|
|
grant delete on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant insert on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant references on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant select on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant trigger on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant truncate on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant update on table "public"."conversaciones_asignatura" to "anon";
|
|
|
|
grant delete on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant insert on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant references on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant select on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant trigger on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant truncate on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant update on table "public"."conversaciones_asignatura" to "authenticated";
|
|
|
|
grant delete on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant insert on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant references on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant select on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant trigger on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant truncate on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant update on table "public"."conversaciones_asignatura" to "postgres";
|
|
|
|
grant delete on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant insert on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant references on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant select on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant trigger on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant truncate on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant update on table "public"."conversaciones_asignatura" to "service_role";
|
|
|
|
grant delete on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant insert on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant references on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant select on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant trigger on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant truncate on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant update on table "public"."conversaciones_plan" to "anon";
|
|
|
|
grant delete on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant insert on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant references on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant select on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant trigger on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant truncate on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant update on table "public"."conversaciones_plan" to "authenticated";
|
|
|
|
grant delete on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant insert on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant references on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant select on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant trigger on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant truncate on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant update on table "public"."conversaciones_plan" to "postgres";
|
|
|
|
grant delete on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
grant insert on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
grant references on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
grant select on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
grant trigger on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
grant truncate on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
grant update on table "public"."conversaciones_plan" to "service_role";
|
|
|
|
|