46 lines
1.9 KiB
SQL
46 lines
1.9 KiB
SQL
create table "notes_attachment" (
|
|
"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,
|
|
"note_id" uuid not null,
|
|
"file_id" uuid not null,
|
|
"attached_by" uuid not null
|
|
);
|
|
|
|
alter table "notes_attachment" add constraint "notes_attachment_org_id_workspace_id_project_id_note_id_file_id_key" unique nulls not distinct ("org_id", "workspace_id", "project_id", "note_id", "file_id");
|
|
|
|
create index "notes_attachment_org_id_workspace_id_project_id_note_id_idx" on "notes_attachment" ("org_id", "workspace_id", "project_id", "note_id");
|
|
|
|
create index "notes_attachment_org_id_workspace_id_project_id_file_id_idx" on "notes_attachment" ("org_id", "workspace_id", "project_id", "file_id");
|
|
|
|
create table "notes_note" (
|
|
"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,
|
|
"title" text not null,
|
|
"body" text not null,
|
|
"created_by" uuid not null
|
|
);
|
|
|
|
create index "notes_note_org_id_workspace_id_project_id_created_by_idx" on "notes_note" ("org_id", "workspace_id", "project_id", "created_by");
|
|
|
|
alter table "notes_attachment" enable row level security;
|
|
|
|
alter table "notes_attachment" force row level security;
|
|
|
|
create policy "notes_attachment_tenant" on "notes_attachment" 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 "notes_note" enable row level security;
|
|
|
|
alter table "notes_note" force row level security;
|
|
|
|
create policy "notes_note_tenant" on "notes_note" using ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid) with check ("org_id" = nullif(current_setting('app.org_id', true), '')::uuid);
|