This commit is contained in:
liaibo
2025-12-06 16:47:17 +08:00
parent 15921bfeb7
commit 9ef8e06d67
75 changed files with 559237 additions and 93 deletions
@@ -0,0 +1,43 @@
create table if not exists public.background_tasks (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users (id) on delete cascade,
document_id uuid references public.documents (id) on delete cascade,
task_type text not null default 'ocr',
status text not null default 'pending',
progress integer not null default 0 check (progress between 0 and 100),
message text,
created_at timestamptz not null default timezone('utc', now()),
updated_at timestamptz not null default timezone('utc', now())
);
create index if not exists background_tasks_user_idx
on public.background_tasks (user_id, created_at desc);
create index if not exists background_tasks_document_idx
on public.background_tasks (document_id, created_at desc);
create or replace function public.set_background_tasks_updated_at()
returns trigger
language plpgsql
security invoker
as $$
begin
new.updated_at := timezone('utc', now());
return new;
end;
$$;
drop trigger if exists set_background_tasks_updated_at on public.background_tasks;
create trigger set_background_tasks_updated_at
before update on public.background_tasks
for each row
execute procedure public.set_background_tasks_updated_at();
alter table public.background_tasks enable row level security;
drop policy if exists "Own background tasks" on public.background_tasks;
create policy "Own background tasks"
on public.background_tasks
for all
using (auth.uid() = user_id)
with check (auth.uid() = user_id);
@@ -0,0 +1,15 @@
-- 允许工作空间成员删除媒体资源,保持与插入/更新策略一致
alter table public.media_assets enable row level security;
drop policy if exists "Delete assets within workspace" on public.media_assets;
create policy "Delete assets within workspace"
on public.media_assets
for delete
using (
exists (
select 1
from public.workspace_members wm
where wm.workspace_id = media_assets.workspace_id
and wm.user_id = auth.uid()
)
);
@@ -0,0 +1,36 @@
alter table public.documents
add column if not exists mindmap_data jsonb,
add column if not exists raw_text text,
add column if not exists index_status text not null default 'pending';
alter table public.documents
alter column index_status set default 'pending';
alter table public.documents
alter column updated_at set default timezone('utc', now());
alter table public.documents
alter column created_at set default timezone('utc', now());
create index if not exists documents_user_updated_idx
on public.documents (user_id, updated_at desc);
create index if not exists documents_index_status_idx
on public.documents (index_status);
create or replace function public.set_documents_updated_at()
returns trigger
language plpgsql
security invoker
as $$
begin
new.updated_at := timezone('utc', now());
return new;
end;
$$;
drop trigger if exists set_documents_updated_at on public.documents;
create trigger set_documents_updated_at
before update on public.documents
for each row
execute procedure public.set_documents_updated_at();