diff db/pubsub.sql @ 294:df1edebb0466

PEP implementation, draft (huge patch sorry): /!\ database schema has changed ! /!\ - whole PEP behaviour is not managed yet - if the stanza is delegated, PEP is assumed - fixed potential SQL injection in pgsql_storage - publish notifications manage PEP - added retract notifications (if "notify" attribute is present), with PEP handling - a publisher can't replace an item he didn't publised anymore - /!\ schema has changed, sat_pubsub_update_0_1.sql update it - sat_pubsub_update_0_1.sql also fixes bad items coming from former version of SàT
author Goffi <goffi@goffi.org>
date Sun, 16 Aug 2015 01:32:42 +0200
parents f0cd02c032b3
children bed30cef11a8
line wrap: on
line diff
--- a/db/pubsub.sql	Sun Aug 16 01:15:13 2015 +0200
+++ b/db/pubsub.sql	Sun Aug 16 01:32:42 2015 +0200
@@ -5,7 +5,8 @@
 
 CREATE TABLE nodes (
     node_id serial PRIMARY KEY,
-    node text NOT NULL UNIQUE,
+    node text NOT NULL,
+	pep text,
     node_type text NOT NULL DEFAULT 'leaf'
         CHECK (node_type IN ('leaf', 'collection')),
     access_model text NOT NULL DEFAULT 'open'
@@ -15,9 +16,15 @@
     send_last_published_item text NOT NULL DEFAULT 'on_sub'
         CHECK (send_last_published_item IN ('never', 'on_sub')),
     publish_model text NOT NULL DEFAULT 'publishers'
-        CHECK (publish_model IN ('publishers', 'subscribers', 'open'))
+        CHECK (publish_model IN ('publishers', 'subscribers', 'open')),
+	UNIQUE (node, pep) WHERE pep IS NOT NULL,
+	UNIQUE (node) WHERE pep IS NULL
 );
 
+/* we need 2 partial indexes to manage NULL value for PEP */
+CREATE UNIQUE INDEX nodes_node_pep_key_not_null ON nodes(node, pep) WHERE pep IS NOT NULL;
+CREATE UNIQUE INDEX nodes_node_pep_key_null ON nodes(node) WHERE pep IS NULL;
+
 INSERT INTO nodes (node, node_type) values ('', 'collection');
 
 CREATE TABLE affiliations (
@@ -68,3 +75,9 @@
     UNIQUE (item_id,groupname)
 );
 
+CREATE TABLE metadata (
+	key text PRIMARY KEY,
+	value text
+);
+
+INSERT INTO metadata VALUES ('version', '1');