Fix file sharing load speed and move error; misc updates
- Remove recursive directory size calculations (single Seafile API call per list) - Remove 'Used in this location' usage display - Fix move using v2 per-type endpoints instead of broken batch endpoint - Send entry type from frontend for correct move routing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+87
-2
@@ -33,6 +33,7 @@ create table public.projects (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
company_id uuid references public.companies(id) on delete cascade not null,
|
||||
name text not null,
|
||||
constraint projects_name_not_blank check (length(trim(name)) > 0),
|
||||
description text default '',
|
||||
status text not null check (status in ('active', 'completed')) default 'active',
|
||||
created_at timestamptz default now() not null
|
||||
@@ -43,6 +44,7 @@ alter table public.projects enable row level security;
|
||||
create table public.tasks (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
project_id uuid references public.projects(id) on delete cascade not null,
|
||||
request_key uuid,
|
||||
title text not null,
|
||||
assigned_to uuid references public.profiles(id) on delete set null,
|
||||
assigned_name text,
|
||||
@@ -58,10 +60,12 @@ alter table public.tasks enable row level security;
|
||||
create table public.submissions (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
task_id uuid references public.tasks(id) on delete cascade not null,
|
||||
request_key uuid,
|
||||
version_number integer not null,
|
||||
type text not null check (type in ('initial', 'revision', 'amendment')) default 'initial',
|
||||
revision_type text check (revision_type in ('fourge_error', 'client_revision')),
|
||||
invoiced boolean not null default false,
|
||||
is_hot boolean not null default false,
|
||||
service_type text default '',
|
||||
deadline date,
|
||||
description text default '',
|
||||
@@ -71,6 +75,17 @@ create table public.submissions (
|
||||
);
|
||||
alter table public.submissions enable row level security;
|
||||
|
||||
create unique index if not exists tasks_request_key_key
|
||||
on public.tasks (request_key)
|
||||
where request_key is not null;
|
||||
|
||||
create unique index if not exists submissions_request_key_key
|
||||
on public.submissions (request_key)
|
||||
where request_key is not null;
|
||||
|
||||
create unique index if not exists projects_company_normalized_name_key
|
||||
on public.projects (company_id, lower(btrim(name)));
|
||||
|
||||
-- Submission Files
|
||||
create table public.submission_files (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
@@ -132,12 +147,62 @@ create table public.invoices (
|
||||
due_date date,
|
||||
total numeric(10,2) default 0,
|
||||
notes text default '',
|
||||
bill_to text,
|
||||
invoice_email text,
|
||||
stripe_fee numeric(10,2),
|
||||
created_by uuid references public.profiles(id) on delete set null,
|
||||
created_at timestamptz default now() not null
|
||||
);
|
||||
alter table public.invoices enable row level security;
|
||||
|
||||
-- Expenses
|
||||
create table public.expenses (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
date date default current_date not null,
|
||||
description text not null,
|
||||
category text not null default 'Other',
|
||||
amount numeric(10,2) not null,
|
||||
notes text default '',
|
||||
receipt_path text,
|
||||
receipt_name text,
|
||||
created_by uuid references public.profiles(id) on delete set null,
|
||||
created_at timestamptz default now() not null
|
||||
);
|
||||
alter table public.expenses enable row level security;
|
||||
create policy "Team all expenses" on public.expenses for all using (get_my_role() = 'team');
|
||||
|
||||
-- Subcontractor Payments (tracked separately, included as contractor expenses)
|
||||
create table public.subcontractor_payments (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
profile_id uuid references public.profiles(id) on delete set null,
|
||||
date date default current_date not null,
|
||||
description text not null,
|
||||
amount numeric(10,2) not null,
|
||||
status text not null default 'pending' check (status in ('pending', 'paid')),
|
||||
paid_at date,
|
||||
notes text default '',
|
||||
created_by uuid references public.profiles(id) on delete set null,
|
||||
created_at timestamptz default now() not null
|
||||
);
|
||||
alter table public.subcontractor_payments enable row level security;
|
||||
create policy "Team all subcontractor_payments" on public.subcontractor_payments
|
||||
for all using (get_my_role() = 'team') with check (get_my_role() = 'team');
|
||||
|
||||
-- Meeting Notes
|
||||
create table public.meeting_notes (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
meeting_at timestamptz default now() not null,
|
||||
title text not null,
|
||||
attendees text default '',
|
||||
notes text not null default '',
|
||||
created_by uuid references public.profiles(id) on delete set null,
|
||||
created_at timestamptz default now() not null,
|
||||
updated_at timestamptz default now() not null
|
||||
);
|
||||
alter table public.meeting_notes enable row level security;
|
||||
create policy "Team all meeting_notes" on public.meeting_notes
|
||||
for all using (get_my_role() = 'team') with check (get_my_role() = 'team');
|
||||
|
||||
-- Invoice Items
|
||||
create table public.invoice_items (
|
||||
id uuid default gen_random_uuid() primary key,
|
||||
@@ -243,9 +308,17 @@ begin
|
||||
|
||||
if caller_role = 'client' then
|
||||
new.project_id := old.project_id;
|
||||
new.assigned_to := old.assigned_to;
|
||||
new.assigned_name := old.assigned_name;
|
||||
new.invoiced := old.invoiced;
|
||||
|
||||
if not (
|
||||
new.status = 'not_started'
|
||||
and coalesce(new.current_version, 0) > coalesce(old.current_version, 0)
|
||||
and new.assigned_to is null
|
||||
and new.assigned_name is null
|
||||
) then
|
||||
new.assigned_to := old.assigned_to;
|
||||
new.assigned_name := old.assigned_name;
|
||||
end if;
|
||||
elsif caller_role = 'external' then
|
||||
new.project_id := old.project_id;
|
||||
new.invoiced := old.invoiced;
|
||||
@@ -474,6 +547,7 @@ insert into storage.buckets (id, name, public) values ('submissions', 'submissio
|
||||
insert into storage.buckets (id, name, public) values ('deliveries', 'deliveries', false);
|
||||
insert into storage.buckets (id, name, public) values ('company-logos', 'company-logos', true);
|
||||
insert into storage.buckets (id, name, public) values ('fourge-files', 'fourge-files', false);
|
||||
insert into storage.buckets (id, name, public) values ('expense-receipts', 'expense-receipts', false);
|
||||
|
||||
-- Company Logos (public bucket — team manages, public can read for embedded URLs in PDFs)
|
||||
create policy "Team manages company logos" on storage.objects
|
||||
@@ -546,6 +620,17 @@ create policy "Team updates fourge files storage" on storage.objects
|
||||
create policy "Team deletes fourge files storage" on storage.objects
|
||||
for delete to authenticated using (bucket_id = 'fourge-files' and get_my_role() = 'team');
|
||||
|
||||
-- Expense Receipts: team-only storage for uploaded expense receipts/photos
|
||||
create policy "Team reads expense receipts storage" on storage.objects
|
||||
for select to authenticated using (bucket_id = 'expense-receipts' and get_my_role() = 'team');
|
||||
create policy "Team inserts expense receipts storage" on storage.objects
|
||||
for insert to authenticated with check (bucket_id = 'expense-receipts' and get_my_role() = 'team');
|
||||
create policy "Team updates expense receipts storage" on storage.objects
|
||||
for update to authenticated using (bucket_id = 'expense-receipts' and get_my_role() = 'team')
|
||||
with check (bucket_id = 'expense-receipts' and get_my_role() = 'team');
|
||||
create policy "Team deletes expense receipts storage" on storage.objects
|
||||
for delete to authenticated using (bucket_id = 'expense-receipts' and get_my_role() = 'team');
|
||||
|
||||
-- ============================================================
|
||||
-- Trigger: auto-create profile on signup
|
||||
-- Team assigns company_id later via the Companies page
|
||||
|
||||
Reference in New Issue
Block a user