Files
accounted/supabase/migrations/20260519130000_transactions_counterparty_iban.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

24 lines
1.1 KiB
SQL

-- Migration: capture counterparty IBAN on transactions for transfer-pairing.
--
-- Why: PSD2 returns the creditor (outflow) or debtor (inflow) account IBAN on
-- every booked transaction, but gnubok hasn't persisted it. Without an IBAN
-- column, intra-account transfers ("move money from SEK 1930 to EUR 1932")
-- can't be auto-detected and end up double-categorized.
--
-- The new column is nullable: SIE imports, manual entries, and pre-existing
-- rows have no IBAN. counterparty_account stays as a fallback for Bankgiro /
-- Plusgiro identifiers when IBAN is absent (Swedish domestic transfers).
--
-- The partial index supports the own-account detector's primary lookup:
-- SELECT ... FROM transactions WHERE company_id = ? AND counterparty_iban = ?
ALTER TABLE public.transactions
ADD COLUMN IF NOT EXISTS counterparty_iban TEXT,
ADD COLUMN IF NOT EXISTS counterparty_account TEXT;
CREATE INDEX IF NOT EXISTS idx_transactions_counterparty_iban
ON public.transactions (company_id, counterparty_iban)
WHERE counterparty_iban IS NOT NULL;
NOTIFY pgrst, 'reload schema';