Files
accounted/supabase/migrations/20260224132419_user_description_matching.sql
T
Jakob Wennberg b0de46790a fix: align local migrations with deployed Supabase state
Rename migration files (039-052) from sequential to real deployed
timestamps, add 11 missing migration files that were applied directly
to production, apply invoice_delivery_note_sequences migration, and
rename placeholder files for clarity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 10:16:22 +01:00

24 lines
983 B
SQL

-- Migration: user_description_matching
-- Adds source tracking, user description text, and template_id to mapping_rules
-- to support user-description-based transaction matching.
--
-- Safe migration: all new columns have defaults or are nullable,
-- so existing rows remain valid.
-- 1. Add source column to track rule origin
ALTER TABLE public.mapping_rules
ADD COLUMN IF NOT EXISTS source TEXT NOT NULL DEFAULT 'auto'
CHECK (source IN ('auto', 'user_description', 'system'));
-- 2. Add user_description column to store the user's plain-language text
ALTER TABLE public.mapping_rules
ADD COLUMN IF NOT EXISTS user_description TEXT;
-- 3. Add template_id column to store the confirmed booking template
ALTER TABLE public.mapping_rules
ADD COLUMN IF NOT EXISTS template_id TEXT;
-- 4. Index for efficient upsert-on-merchant lookup by source
CREATE INDEX IF NOT EXISTS idx_mapping_rules_user_merchant_source
ON public.mapping_rules (user_id, merchant_pattern, source);