1
|
/**
|
2
|
* Restore archived documents
|
3
|
*/
|
4
|
|
5
|
/* Gather most recent docids from xml_revisions that
|
6
|
* 1. do not have systemMetadata.archived=true
|
7
|
* 2. do not exist in xml_documents
|
8
|
* */
|
9
|
CREATE TABLE restore_documents (
|
10
|
docid VARCHAR(250),
|
11
|
rev INT8,
|
12
|
rootnodeid INT8,
|
13
|
guid text
|
14
|
);
|
15
|
INSERT INTO restore_documents (
|
16
|
docid,
|
17
|
rev,
|
18
|
rootnodeid,
|
19
|
guid
|
20
|
)
|
21
|
SELECT
|
22
|
x.docid,
|
23
|
x.rev,
|
24
|
x.rootnodeid,
|
25
|
id.guid
|
26
|
FROM
|
27
|
xml_revisions x,
|
28
|
identifier id,
|
29
|
systemMetadata sm
|
30
|
WHERE x.docid = id.docid
|
31
|
AND x.rev = id.rev
|
32
|
AND id.guid = sm.guid
|
33
|
-- TODO: hone the criteria for selecting documents to restore
|
34
|
AND sm.archived = true
|
35
|
AND sm.obsoletedBy is not null;
|
36
|
|
37
|
/* Move xml_revisions back into xml_documents for the affected docids
|
38
|
*/
|
39
|
INSERT INTO xml_documents
|
40
|
(docid, rootnodeid, docname, doctype,
|
41
|
user_owner, user_updated, date_created, date_updated,
|
42
|
server_location, rev, public_access, catalog_id)
|
43
|
SELECT
|
44
|
docid, rootnodeid, docname, doctype,
|
45
|
user_owner, user_updated , date_created, date_updated,
|
46
|
server_location, rev, public_access, catalog_id
|
47
|
FROM xml_revisions x, restore_documents rd
|
48
|
WHERE x.rootnodeid = rd.rootnodeid;
|
49
|
|
50
|
/* Move xml_nodes_revisions back into xml_nodes for the affected docids
|
51
|
*/
|
52
|
INSERT INTO xml_nodes
|
53
|
(nodeid, nodeindex, nodetype, nodename, nodeprefix,
|
54
|
nodedata, parentnodeid, rootnodeid, docid, date_created,
|
55
|
date_updated, nodedatanumerical, nodedatadate)
|
56
|
SELECT
|
57
|
nodeid, nodeindex, nodetype, nodename, nodeprefix,
|
58
|
nodedata, parentnodeid, rootnodeid, docid, date_created,
|
59
|
date_updated, nodedatanumerical, nodedatadate
|
60
|
FROM xml_nodes_revisions x, restore_documents rd
|
61
|
WHERE x.rootnodeid = rd.rootnodeid;
|
62
|
|
63
|
/* Ensure previous revisions of docids do not have systemMetadata.archived=true
|
64
|
* (Avoids encountering this issue again)
|
65
|
*/
|
66
|
UPDATE systemMetadata sm
|
67
|
SET sm.archived = false
|
68
|
FROM restore_documents rd
|
69
|
WHERE sm.guid = rd.guid;
|
70
|
|
71
|
/* Clean up
|
72
|
*/
|
73
|
DROP TABLE restore_documents;
|
74
|
|
75
|
/*
|
76
|
* update the database version
|
77
|
*/
|
78
|
UPDATE db_version SET status=0;
|
79
|
|
80
|
INSERT INTO db_version (version, status, date_created)
|
81
|
VALUES ('2.4.0', 1, CURRENT_DATE);
|