From 717349c3e383fae954b39a97f5bea115965f927a Mon Sep 17 00:00:00 2001
From: einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>
Date: Thu, 12 Jul 2007 20:56:23 +0000
Subject: Adding partial unique index on partnumber to prevent multiple active
 items sharing the same part number

git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1391 4979c152-3d1c-0410-bac9-87ea11338e46
---
 sql/Pg-database.sql | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

(limited to 'sql/Pg-database.sql')

diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql
index 3533708e..00d9d86a 100644
--- a/sql/Pg-database.sql
+++ b/sql/Pg-database.sql
@@ -531,6 +531,9 @@ CREATE TABLE parts (
   project_id int,
   avgcost NUMERIC
 );
+
+CREATE UNIQUE INDEX parts_partnumber_index_u ON parts (partnumber) 
+WHERE obsolete is false;
 --
 CREATE TABLE assembly (
   id int,
@@ -622,7 +625,7 @@ CREATE TABLE partstax (
   chart_id int,
   taxcategory_id int,
   PRIMARY KEY (parts_id, chart_id),
-  FOREIGN KEY (parts_id) REFERENCES parts (id),
+  FOREIGN KEY (parts_id) REFERENCES parts (id) on delete cascade,
   FOREIGN KEY (chart_id) REFERENCES chart (id),
   FOREIGN KEY (taxcategory_id) REFERENCES taxcategory (taxcategory_id)
 );
-- 
cgit v1.2.3

