سامانه صدور فاکتور و حسابداری

Prepare concurrency-safe accounting master uniqueness

davoodmehraban89 committed Sep 29, 2026 at 22:42 UTC 045ee66bb0fe19b35137322a84043353f1cc8850
1 file changed +30
supabase/migrations/20260929190500_accounting_master_uniqueness.sql new
+30
@@ -0,0 +1,30 @@
1 +-- PREPARED, NOT YET APPLIED: requires explicit schema-change approval.
2 +-- Concurrency-safe uniqueness for accounting/master-data business keys.
3 +
4 +create unique index if not exists ux_finora_account_code
5 +on public.records(owner_id,(data->>'companyId'),upper(data->>'code'))
6 +where collection='accounts' and coalesce(data->>'code','')<>'';
7 +
8 +create unique index if not exists ux_finora_dimension_type_code
9 +on public.records(owner_id,(data->>'companyId'),upper(data->>'code'))
10 +where collection='dimensionTypes' and coalesce(data->>'code','')<>'';
11 +
12 +create unique index if not exists ux_finora_dimension_value_code
13 +on public.records(owner_id,(data->>'companyId'),(data->>'dimensionTypeId'),upper(data->>'code'))
14 +where collection='dimensionValues' and coalesce(data->>'code','')<>'';
15 +
16 +create unique index if not exists ux_finora_branch_code
17 +on public.records(owner_id,(data->>'companyId'),upper(data->>'code'))
18 +where collection='branches' and coalesce(data->>'code','')<>'';
19 +
20 +create unique index if not exists ux_finora_project_code
21 +on public.records(owner_id,(data->>'companyId'),upper(data->>'code'))
22 +where collection='projects' and coalesce(data->>'code','')<>'';
23 +
24 +create unique index if not exists ux_finora_cost_center_code
25 +on public.records(owner_id,(data->>'companyId'),upper(data->>'code'))
26 +where collection='costCenters' and coalesce(data->>'code','')<>'';
27 +
28 +create unique index if not exists ux_finora_contract_number
29 +on public.records(owner_id,(data->>'companyId'),upper(data->>'number'))
30 +where collection='contracts' and coalesce(data->>'number','')<>'';