-- Additive support for local customer merges. No existing rows are changed. ALTER TABLE customers ADD COLUMN IF NOT EXISTS merged_into_customer_id INTEGER REFERENCES customers(id); CREATE TABLE IF NOT EXISTS customer_merge_history ( id BIGSERIAL PRIMARY KEY, target_customer_id INTEGER NOT NULL REFERENCES customers(id), source_customer_ids INTEGER[] NOT NULL, actor_id INTEGER NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), snapshot JSONB NOT NULL, movements JSONB NOT NULL );