summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-01-01 19:01:38 +0100
committerYorhel <git@yorhel.nl>2010-01-01 19:01:38 +0100
commit81380525f2c4385577019ae964039dcf3c791625 (patch)
treebb39439553ecbf76d34b971c688225d5d2047238 /util
parent0a4395eb4b186ea91e7a69d1556cb50352ade7f7 (diff)
SQL: Revision insertion abstraction for producer entries
Diffstat (limited to 'util')
-rw-r--r--util/updates/update_2.10.sql39
1 files changed, 39 insertions, 0 deletions
diff --git a/util/updates/update_2.10.sql b/util/updates/update_2.10.sql
index 4ae4160b..2219bb57 100644
--- a/util/updates/update_2.10.sql
+++ b/util/updates/update_2.10.sql
@@ -362,3 +362,42 @@ END;
$$ LANGUAGE plpgsql;
+CREATE OR REPLACE FUNCTION edit_producer_init(cid integer) RETURNS void AS $$
+BEGIN
+ CREATE TEMPORARY TABLE edit_producer (LIKE producers_rev INCLUDING DEFAULTS INCLUDING CONSTRAINTS);
+ ALTER TABLE edit_producer DROP COLUMN id;
+ ALTER TABLE edit_producer DROP COLUMN pid;
+ CREATE TEMPORARY TABLE edit_producer_relations (LIKE producers_relations INCLUDING DEFAULTS INCLUDING CONSTRAINTS);
+ ALTER TABLE edit_producer_relations DROP COLUMN pid1;
+ ALTER TABLE edit_producer_relations RENAME COLUMN pid2 TO pid;
+ -- new producer
+ IF cid IS NULL THEN
+ PERFORM edit_revtable('p', NULL);
+ INSERT INTO edit_producer DEFAULT VALUES;
+ -- load revision
+ ELSE
+ PERFORM edit_revtable('p', (SELECT pid FROM producers_rev WHERE id = cid));
+ INSERT INTO edit_producer SELECT type, name, original, website, lang, "desc", alias, l_wp FROM producers_rev WHERE id = cid;
+ INSERT INTO edit_producer_relations SELECT pid2, relation FROM producers_relations WHERE pid1 = cid;
+ END IF;
+END;
+$$ LANGUAGE plpgsql;
+
+
+CREATE OR REPLACE FUNCTION edit_producer_commit() RETURNS edit_rettype AS $$
+DECLARE
+ r edit_rettype;
+BEGIN
+ IF (SELECT COUNT(*) FROM edit_producer) <> 1 THEN
+ RAISE 'edit_producer must have exactly one row!';
+ END IF;
+ SELECT INTO r * FROM edit_commit();
+ INSERT INTO producers_rev SELECT r.cid, r.iid, type, name, original, website, lang, "desc", alias, l_wp FROM edit_producer;
+ INSERT INTO producers_relations SELECT r.cid, pid, relation FROM edit_producer_relations;
+ UPDATE producers SET latest = r.cid WHERE id = r.iid;
+ DROP TABLE edit_revision, edit_producer, edit_producer_relations;
+ RETURN r;
+END;
+$$ LANGUAGE plpgsql;
+
+