summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-09-19 02:46:01 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-09-19 02:46:01 +0000
commit8449cce4451570fc8a0cd2df3565e0d0de0b7fae (patch)
tree4aa3f695ed95777771a9d4f445729c741fd56786 /sql
parent58a7f11ce7a5e958e1876019b1e035f7bdc1cb24 (diff)
Committing db fixes from Seneca
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@115 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'sql')
-rwxr-xr-xsql/Pg-functions.sql12
-rw-r--r--sql/Pg-upgrade-2.6.17-2.6.18.sql14
2 files changed, 19 insertions, 7 deletions
diff --git a/sql/Pg-functions.sql b/sql/Pg-functions.sql
index e3689fd6..ee70b0e7 100755
--- a/sql/Pg-functions.sql
+++ b/sql/Pg-functions.sql
@@ -281,8 +281,14 @@ BEGIN
EXECUTE ''SELECT TABLE_ID FROM custom_table_catalog
WHERE extends = '''''' || table_name || '''''' '';
IF NOT FOUND THEN
- INSERT INTO custom_table_catalog (extends) VALUES (table_name);
- EXECUTE ''CREATE TABLE custom_''||table_name || '' ()'';
+ BEGIN
+ INSERT INTO custom_table_catalog (extends)
+ VALUES (table_name);
+ EXECUTE ''CREATE TABLE custom_''||table_name ||
+ '' (row_id INT)'';
+ EXCEPTION WHEN duplicate_table THEN
+ -- do nothing
+ END;
END IF;
EXECUTE ''INSERT INTO custom_field_catalog (field_name, table_id)
VALUES ( '''''' || new_field_name ||'''''', (SELECT table_id FROM custom_table_catalog
@@ -305,7 +311,7 @@ BEGIN
table_id = (SELECT table_id FROM custom_table_catalog
WHERE extends = table_name);
EXECUTE ''ALTER TABLE custom_'' || table_name ||
- '' DROP COLUMN '' || field_name;
+ '' DROP COLUMN '' || custom_field_name;
RETURN TRUE;
END;
' LANGUAGE PLPGSQL;
diff --git a/sql/Pg-upgrade-2.6.17-2.6.18.sql b/sql/Pg-upgrade-2.6.17-2.6.18.sql
index 8144f1df..75cd02ab 100644
--- a/sql/Pg-upgrade-2.6.17-2.6.18.sql
+++ b/sql/Pg-upgrade-2.6.17-2.6.18.sql
@@ -1,3 +1,4 @@
+ALTER TABLE chart ADD PRIMARY KEY (id);
-- linuxpoet:
-- adding primary key to acc_trans
-- We are using standard postgresql names for the sequence for consistency as we move forward
@@ -110,7 +111,7 @@ DO ALSO INSERT INTO transaction_ledger (id, table_name) VALUES (new.id, 'ap');
CREATE RULE ap_id_track_u AS ON update TO ap
DO ALSO UPDATE transaction_ledger SET id = new.id WHERE id = old.id;
-insert into transaction_ledger (id, table_name) SELECT id, 'ar' FROM ap;
+insert into transaction_ledger (id, table_name) SELECT id, 'ar' FROM ar;
CREATE RULE ar_id_track_i AS ON insert TO ar
DO ALSO INSERT INTO transaction_ledger (id, table_name) VALUES (new.id, 'ar');
@@ -246,8 +247,13 @@ BEGIN
EXECUTE ''SELECT TABLE_ID FROM custom_table_catalog
WHERE extends = '''''' || table_name || '''''' '';
IF NOT FOUND THEN
- INSERT INTO custom_table_catalog (extends) VALUES (table_name);
- EXECUTE ''CREATE TABLE custom_''||table_name || '' ()'';
+ BEGIN
+ INSERT INTO custom_table_catalog (extends) VALUES (table_name);
+ EXECUTE ''CREATE TABLE custom_''||table_name ||
+ '' (row_id INT)'';
+ EXCEPTION WHEN duplicate_table THEN
+ -- do nothing
+ END;
END IF;
EXECUTE ''INSERT INTO custom_field_catalog (field_name, table_id)
VALUES ( '''''' || new_field_name ||'''''', (SELECT table_id FROM custom_table_catalog
@@ -270,7 +276,7 @@ BEGIN
table_id = (SELECT table_id FROM custom_table_catalog
WHERE extends = table_name);
EXECUTE ''ALTER TABLE custom_'' || table_name ||
- '' DROP COLUMN '' || field_name;
+ '' DROP COLUMN '' || custom_field_name;
RETURN TRUE;
END;
' LANGUAGE PLPGSQL;