summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/Pg-database.sql23
-rw-r--r--sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql10
2 files changed, 27 insertions, 6 deletions
diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql
index 907ce363..b7d23a3d 100644
--- a/sql/Pg-database.sql
+++ b/sql/Pg-database.sql
@@ -241,17 +241,28 @@ CREATE TABLE ap (
terms int2 DEFAULT 0
);
--
-CREATE TABLE partstax (
- parts_id int,
- chart_id int,
- PRIMARY KEY (parts_id, chart_id)
-);
---
CREATE TABLE taxmodule (
taxmodule_id serial PRIMARY KEY,
taxmodulename text NOT NULL
);
--
+CREATE TABLE taxcategory (
+ taxcategory_id serial PRIMARY KEY,
+ taxcategoryname text NOT NULL,
+ taxmodule_id int NOT NULL,
+ FOREIGN KEY taxmodule_id REFERENCES taxmodule (taxmodule_id)
+);
+--
+CREATE TABLE partstax (
+ parts_id int,
+ chart_id int,
+ taxcategory_id int,
+ PRIMARY KEY (parts_id, chart_id),
+ FOREIGN KEY parts_id REFERENCES parts (id),
+ FOREIGN KEY chart_id REFERENCES chart (id),
+ FOREIGN KEY taxcategory_id REFERENCES taxcategory (taxcategory_id)
+);
+--
CREATE TABLE tax (
chart_id int PRIMARY KEY,
rate numeric,
diff --git a/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql b/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
index 90e7e313..9594f9a0 100644
--- a/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
+++ b/sql/legacy/Pg-upgrade-2.6.18-2.6.19.sql
@@ -43,6 +43,8 @@ ALTER TABLE parts ADD PRIMARY KEY (id);
ALTER TABLE partsgroup ADD PRIMARY KEY (id);
ALTER TABLE partstax ADD PRIMARY KEY (parts_id, chart_id);
+ALTER TABLE partstax ADD FOREIGN KEY (chart_id) REFERENCES chart (id);
+ALTER TABLE partstax ADD FOREIGN KEY (parts_id) REFERENCES parts (id);
ALTER TABLE pricegroup ADD PRIMARY KEY (id);
@@ -132,6 +134,14 @@ INSERT INTO taxmodule (
1, 'Simple'
);
+CREATE TABLE taxcategory (
+ taxcategory_id serial PRIMARY KEY,
+ taxcategoryname text NOT NULL,
+ taxmodule_id int NOT NULL REFERENCES taxmodule (taxmodule_id)
+);
+
+ALTER TABLE partstax ADD COLUMN taxcategory_id int REFERENCES taxcategory (taxcategory_id);
+
LOCK tax IN EXCLUSIVE MODE;
ALTER TABLE tax ADD COLUMN pass int DEFAULT 0;
UPDATE tax SET pass = 0;