alter table "public"."brains" alter column "brain_type" drop default;

alter type "public"."brain_type_enum" rename to "brain_type_enum__old_version_to_be_dropped";

create type "public"."brain_type_enum" as enum ('doc', 'api', 'composite', 'integration');

create table "public"."integrations" (
    "created_at" timestamp with time zone not null default now(),
    "integration_name" text not null,
    "integration_logo_url" text,
    "connection_settings" jsonb,
    "id" uuid not null default gen_random_uuid()
);


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

create table "public"."integrations_user" (
    "id" bigint generated by default as identity not null,
    "created_at" timestamp with time zone not null default now(),
    "user_id" uuid not null,
    "brain_id" uuid,
    "integration_id" uuid,
    "settings" jsonb,
    "credentials" jsonb
);


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

alter table "public"."brains" alter column brain_type type "public"."brain_type_enum" using brain_type::text::"public"."brain_type_enum";

alter table "public"."brains" alter column "brain_type" set default 'doc'::brain_type_enum;

drop type "public"."brain_type_enum__old_version_to_be_dropped";

alter table "public"."brains" alter column "model" set default 'gpt-3.5-turbo-1106'::text;

alter table "public"."brains_vectors" add column "id" uuid not null default gen_random_uuid();

alter table "public"."brains_vectors" alter column "vector_id" set not null;

alter table "public"."knowledge" add column "integration" text;

alter table "public"."knowledge" add column "integration_link" text;

alter table "public"."user_settings" alter column "models" set default '["gpt-3.5-turbo-0125"]'::jsonb;

CREATE UNIQUE INDEX brains_vectors_pkey ON public.brains_vectors USING btree (id);

CREATE UNIQUE INDEX integrations_id_key ON public.integrations USING btree (id);

CREATE UNIQUE INDEX integrations_integration_name_key ON public.integrations USING btree (integration_name);

CREATE UNIQUE INDEX integrations_pkey ON public.integrations USING btree (id);

CREATE UNIQUE INDEX integrations_user_pkey ON public.integrations_user USING btree (id);

alter table "public"."brains_vectors" add constraint "brains_vectors_pkey" PRIMARY KEY using index "brains_vectors_pkey";

alter table "public"."integrations" add constraint "integrations_pkey" PRIMARY KEY using index "integrations_pkey";

alter table "public"."integrations_user" add constraint "integrations_user_pkey" PRIMARY KEY using index "integrations_user_pkey";

alter table "public"."integrations" add constraint "integrations_id_key" UNIQUE using index "integrations_id_key";

alter table "public"."integrations" add constraint "integrations_integration_name_key" UNIQUE using index "integrations_integration_name_key";

alter table "public"."integrations_user" add constraint "integrations_user_brain_id_fkey" FOREIGN KEY (brain_id) REFERENCES brains(brain_id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."integrations_user" validate constraint "integrations_user_brain_id_fkey";

alter table "public"."integrations_user" add constraint "integrations_user_integration_id_fkey" FOREIGN KEY (integration_id) REFERENCES integrations(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."integrations_user" validate constraint "integrations_user_integration_id_fkey";

alter table "public"."integrations_user" add constraint "integrations_user_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."integrations_user" validate constraint "integrations_user_user_id_fkey";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


