From 1250e797afd9a206a1dc579601429c2af91de388 Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 28 Dec 2007 02:40:43 +0000 Subject: Adding a fix script for the primary key to the tax table git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@2011 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/fixes/tax_pkey_duplicate.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sql/fixes/tax_pkey_duplicate.sql diff --git a/sql/fixes/tax_pkey_duplicate.sql b/sql/fixes/tax_pkey_duplicate.sql new file mode 100644 index 00000000..f590d8ca --- /dev/null +++ b/sql/fixes/tax_pkey_duplicate.sql @@ -0,0 +1,13 @@ +-- SC: Replaces the primary key of the tax table with a check for if the +-- combination of chart_id and validto is unique. An index is added to +-- check for the case of multiple NULL validto values and fail if that would +-- result. + +ALTER TABLE tax DROP CONSTRAINT tax_pkey; +ALTER TABLE tax ADD CONSTRAINT tax_unique UNIQUE (chart_id, validto); +COMMENT ON CONSTRAINT tax_unique ON tax IS +$$Checks on the base uniqueness of the chart_id, validto combination$$; + +CREATE UNIQUE INDEX tax_null_validto_unique_idx ON tax(chart_id) WHERE validto IS NULL; +COMMENT ON INDEX tax_null_validto_unique_idx ON tax IS +$$Part of primary key emulation for the tax table, ensures at most one NULL validto for each chart_id$$; -- cgit v1.2.3