Files
accounted/supabase/migrations/20260511120000_bank_connections_pending_selection.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

32 lines
1.1 KiB
SQL

-- Add 'pending_selection' to bank_connections.status CHECK constraint.
--
-- New PSD2 connections start in 'pending_selection' so the user can pick
-- which accounts to actually sync before any transactions are pulled.
-- Once the user confirms their selection the connection flips to 'active'.
ALTER TABLE public.bank_connections
DROP CONSTRAINT IF EXISTS bank_connections_status_check;
ALTER TABLE public.bank_connections
ADD CONSTRAINT bank_connections_status_check
CHECK (status IN ('pending', 'pending_selection', 'active', 'expired', 'error', 'revoked'));
-- Backfill existing rows: every account gets enabled=true so current
-- connections keep syncing exactly the accounts they were syncing before.
-- Users can later prune accounts via the picker dialog.
UPDATE public.bank_connections
SET accounts_data = (
SELECT jsonb_agg(
CASE
WHEN elem ? 'enabled' THEN elem
ELSE elem || jsonb_build_object('enabled', true)
END
)
FROM jsonb_array_elements(accounts_data) AS elem
)
WHERE accounts_data IS NOT NULL
AND jsonb_typeof(accounts_data) = 'array'
AND jsonb_array_length(accounts_data) > 0;
NOTIFY pgrst, 'reload schema';