Mercurial > libervia-pubsub
annotate db/sat_pubsub_update_0_1.sql @ 378:22832c1d2827
storage (pgsql): don't specify table name in ORDER BY clause as it can cause troubles in some requests.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 12 Jan 2019 16:41:45 +0100 |
parents | 4d4575911060 |
children | 1dc606612405 |
rev | line source |
---|---|
350 | 1 -- we check version of the database before doing anything |
2 -- and stop execution if not good | |
3 \set ON_ERROR_STOP | |
4 DO $$ | |
5 DECLARE ver text; | |
6 BEGIN | |
7 SELECT value INTO ver FROM metadata WHERE key='version'; | |
8 IF FOUND THEN | |
9 RAISE EXCEPTION 'This update file need to be applied on older database, you don''t have to use it'; | |
10 END IF; | |
11 END$$; | |
12 \unset ON_ERROR_STOP | |
13 -- end of version check | |
14 | |
15 | |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 ALTER TABLE nodes ADD COLUMN pep text; |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 ALTER TABLE nodes DROP CONSTRAINT nodes_node_key; |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 /* we need 2 partial indexes to manage NULL value for PEP */ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 CREATE UNIQUE INDEX nodes_node_pep_key_not_null ON nodes(node, pep) WHERE pep IS NOT NULL; |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 CREATE UNIQUE INDEX nodes_node_pep_key_null ON nodes(node) WHERE pep IS NULL; |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 CREATE TABLE metadata ( |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 key text PRIMARY KEY, |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 value text |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 ); |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 INSERT INTO metadata VALUES ('version', '1'); |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
301
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
30 CREATE TABLE item_categories ( |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
31 item_categories_id serial PRIMARY KEY, |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
32 item_id integer NOT NULL references items ON DELETE CASCADE, |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
33 category text NOT NULL, |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
34 UNIQUE (item_id,category) |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
35 ); |
05c875a13a62
categories are now stored in a dedicated table if item contain an atom entry:
Goffi <goffi@goffi.org>
parents:
294
diff
changeset
|
36 |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 UPDATE nodes SET node='urn:xmpp:microblog:0', pep=substring(node from 20) WHERE node LIKE 'urn:xmpp:groupblog:_%'; |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
350 | 39 /* This is to update namespaces, SàT was buggy before 0.6 and didn't set the atom namespace in <entry/> */ |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 /* But yeah, this is a crazy query */ |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 UPDATE items SET data = xmlelement(name item, xmlattributes((xpath('/item/@id', data::xml))[1] as id), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 XMLPARSE(CONTENT NULLIF(array_to_string(xpath('/item/entry/preceding-sibling::*', data::xml)::text[],''),'')), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 xmlelement(name entry, xmlattributes('http://www.w3.org/2005/Atom' as xmlns), array_to_string(xpath('/item/entry/*', data::xml)::text[], '')::xml), |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 XMLPARSE(CONTENT NULLIF(array_to_string(xpath('/item/entry/following-sibling::*', data::xml)::text[],''),''))) |
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 FROM nodes WHERE nodes.node_id = items.node_id |
303
3c2705199108
sat_pubsub_update_0_1.sql now also updates comment nodes
Goffi <goffi@goffi.org>
parents:
301
diff
changeset
|
46 AND (node = 'urn:xmpp:microblog:0' or node LIKE 'urn:xmpp:comments:%') |
294
df1edebb0466
PEP implementation, draft (huge patch sorry):
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 AND XMLEXISTS('/item/entry' PASSING (data::xml)); |