summaryrefslogtreecommitdiff
path: root/sql/fixes/tax_pkey_duplicate.sql
blob: 23876ac038a08768729a85e22ea54e4ced8c9b91 (plain)
  1. -- SC: Replaces the primary key of the tax table with a check for if the
  2. -- combination of chart_id and validto is unique. An index is added to
  3. -- check for the case of multiple NULL validto values and fail if that would
  4. -- result.
  5. ALTER TABLE tax DROP CONSTRAINT tax_pkey;
  6. ALTER TABLE tax ADD CONSTRAINT tax_unique UNIQUE (chart_id, validto);
  7. COMMENT ON CONSTRAINT tax_unique ON tax IS
  8. $$Checks on the base uniqueness of the chart_id, validto combination$$;
  9. CREATE UNIQUE INDEX tax_null_validto_unique_idx ON tax(chart_id) WHERE validto IS NULL;
  10. COMMENT ON INDEX tax_null_validto_unique_idx IS
  11. $$Part of primary key emulation for the tax table, ensures at most one NULL validto for each chart_id$$;