69 lines
2.7 KiB
SQL
69 lines
2.7 KiB
SQL
-- SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
|
create table "knowledge_collection" (
|
|
"id" uuid primary key,
|
|
"version" integer not null,
|
|
"created_at" timestamptz not null,
|
|
"updated_at" timestamptz not null,
|
|
"org_id" uuid not null,
|
|
"workspace_id" uuid not null,
|
|
"project_id" uuid not null,
|
|
"name" text not null,
|
|
"created_by" text not null
|
|
);
|
|
|
|
alter table "knowledge_collection" add constraint "knowledge_collection_org_id_workspace_id_project_id_name_key" unique nulls not distinct ("org_id", "workspace_id", "project_id", "name");
|
|
|
|
create table "knowledge_config" (
|
|
"id" uuid primary key,
|
|
"version" integer not null,
|
|
"created_at" timestamptz not null,
|
|
"updated_at" timestamptz not null,
|
|
"org_id" uuid not null,
|
|
"enabled" boolean not null,
|
|
"backend" text not null,
|
|
"source" text not null,
|
|
"service_id" text,
|
|
"url" text,
|
|
"updated_by" text not null,
|
|
"configured_at" text not null
|
|
);
|
|
|
|
create table "knowledge_document" (
|
|
"id" uuid primary key,
|
|
"version" integer not null,
|
|
"created_at" timestamptz not null,
|
|
"updated_at" timestamptz not null,
|
|
"org_id" uuid not null,
|
|
"workspace_id" uuid not null,
|
|
"project_id" uuid not null,
|
|
"collection_name" text not null,
|
|
"file_id" uuid not null,
|
|
"filename" text not null,
|
|
"status" text not null,
|
|
"error" text,
|
|
"indexed_at" text,
|
|
"requested_by" text not null
|
|
);
|
|
|
|
alter table "knowledge_document" add constraint "knowledge_document_org_id_workspace_id_project_id_12648b24_key" unique nulls not distinct ("org_id", "workspace_id", "project_id", "collection_name", "file_id");
|
|
|
|
create index "knowledge_document_org_id_workspace_id_project_id_ec03a581_idx" on "knowledge_document" ("org_id", "workspace_id", "project_id", "collection_name");
|
|
|
|
alter table "knowledge_collection" enable row level security;
|
|
|
|
alter table "knowledge_collection" force row level security;
|
|
|
|
create policy "knowledge_collection_tenant" on "knowledge_collection" using ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid) with check ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid);
|
|
|
|
alter table "knowledge_config" enable row level security;
|
|
|
|
alter table "knowledge_config" force row level security;
|
|
|
|
create policy "knowledge_config_tenant" on "knowledge_config" using ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid) with check ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid);
|
|
|
|
alter table "knowledge_document" enable row level security;
|
|
|
|
alter table "knowledge_document" force row level security;
|
|
|
|
create policy "knowledge_document_tenant" on "knowledge_document" using ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid) with check ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid);
|