-- Platform associations keep per-association charts (codes can repeat across
-- associations and even within a company), so the global (account_number,
-- accounting_system) uniqueness must not apply to platform-tagged rows. Make it
-- a partial index covering only buildium/zoho (their existing dedupe behavior).
drop index if exists public.chart_of_accounts_number_per_system_unique;
create unique index chart_of_accounts_number_per_system_unique
  on public.chart_of_accounts (account_number, accounting_system)
  where accounting_system <> 'platform';
