Files
fourge-portal/supabase/migrations/20260421103000_add_subcontractor_po_items.sql
Krao Hasanee eee0885811 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>
2026-05-13 14:20:38 -04:00

34 lines
1.3 KiB
SQL

create table if not exists public.subcontractor_po_items (
id uuid default gen_random_uuid() primary key,
po_id uuid references public.subcontractor_payments(id) on delete cascade not null,
task_id uuid references public.tasks(id) on delete set null,
description text not null,
amount numeric(10,2) not null,
sort_order integer default 0 not null,
created_at timestamptz default now() not null
);
alter table public.subcontractor_po_items enable row level security;
drop policy if exists "Team all subcontractor_po_items" on public.subcontractor_po_items;
create policy "Team all subcontractor_po_items" on public.subcontractor_po_items
for all using (get_my_role() = 'team') with check (get_my_role() = 'team');
drop policy if exists "External reads own subcontractor_po_items" on public.subcontractor_po_items;
create policy "External reads own subcontractor_po_items" on public.subcontractor_po_items
for select using (
get_my_role() = 'external'
and po_id in (
select id from public.subcontractor_payments
where profile_id = auth.uid()
)
);
insert into public.subcontractor_po_items (po_id, task_id, description, amount, sort_order)
select id, null, description, amount, 0
from public.subcontractor_payments sp
where not exists (
select 1 from public.subcontractor_po_items item
where item.po_id = sp.id
);