bmc_hub/migrations/999_fix_cvr_unique_constraint.sql

17 lines
683 B
MySQL
Raw Normal View History

2026-08-25 06:43:31 +02:00
-- Migration: Remove the legacy CVR uniqueness rule.
-- CVR is company metadata and multiple e-conomic customer records may
-- legitimately share the same value. This mirrors migration 1000 and keeps
-- this historical migration safe when schema detection selects it again.
-- Drop old unique constraint
ALTER TABLE customers DROP CONSTRAINT IF EXISTS customers_cvr_number_key;
2026-08-25 06:43:31 +02:00
DROP INDEX IF EXISTS customers_cvr_number_unique_idx;
2026-08-25 06:43:31 +02:00
CREATE INDEX IF NOT EXISTS idx_customers_cvr
ON customers(cvr_number)
WHERE cvr_number IS NOT NULL AND cvr_number <> '';
COMMENT ON COLUMN customers.cvr_number IS
'Danish CVR number. Informational/searchable; duplicates are allowed.';