Project

General

Profile

1 5371 berkley
CREATE TABLE systemMetadata (
2
   guid   VARCHAR2(2000),    -- the globally unique string identifier
3 6561 leinfelder
   serial_version VARCHAR2(256), --the serial version of the object
4 5887 berkley
   date_uploaded DATE, -- the date/time the document was first submitted
5
   rights_holder VARCHAR2(250), --the user who has rights to the document, usually the first persons to upload it
6
   checksum VARCHAR2(512), --the checksum of the doc using the given algorithm (see below)
7
   checksum_algorithm VARCHAR2(250), --the algorithm used to calculate the checksum
8
   origin_member_node VARCHAR2(250), --the member node where the document was first uploaded
9
   authoritive_member_node VARCHAR2(250), --the member node that currently controls the document
10
   date_modified DATE, -- the last date/time that the file was changed
11 5917 berkley
   submitter VARCHAR2(256), -- the user who originally submitted the doc
12
   object_format VARCHAR2(256), --the format of the object
13 6136 leinfelder
   size VARCHAR2(256), --the size of the object
14 6766 leinfelder
   archived boolean,	 -- specifies whether this an archived object
15 6136 leinfelder
   replication_allowed boolean,	 -- replication allowed
16
   number_replicas NUMBER(8), 	-- the number of replicas allowed
17 6375 leinfelder
   obsoletes   VARCHAR2(2000),    -- the identifier of the record that this replaces
18
   obsoleted_by   VARCHAR2(2000),    -- the identifier of the record that replaces this record
19 6136 leinfelder
   CONSTRAINT systemMetadata_pk
20
		PRIMARY KEY (guid)
21 5371 berkley
)
22
23 6136 leinfelder
CREATE TABLE systemMetadataReplicationPolicy (
24
	guid VARCHAR2(2000),	-- the globally unique string identifier of the object that the system metadata describes
25
	member_node VARCHAR(250),	 -- replication member node
26
	policy VARCHAR2(2000),	 -- the policy (preferred, blocked, etc...TBD)
27
	CONSTRAINT systemMetadataReplicationPolicy_fk
28
		FOREIGN KEY (guid) REFERENCES systemMetadata
29
);
30
31
CREATE TABLE systemMetadataReplicationStatus (
32
	guid VARCHAR2(2000),	-- the globally unique string identifier of the object that the system metadata describes
33
	member_node VARCHAR(250),	 -- replication member node
34
	status VARCHAR(250),	 -- replication status
35
	date_verified DATE, 	-- the date replication was verified
36
	CONSTRAINT systemMetadataReplicationStatus_fk
37
		FOREIGN KEY (guid) REFERENCES systemMetadata
38
);
39
40 6583 leinfelder
DROP TABLE identifier;
41
42 5276 jones
CREATE TABLE identifier (
43
   guid   VARCHAR2(2000), -- the globally unique string identifier
44
   docid  VARCHAR2(250),  -- the local document id #
45
   rev    NUMBER(8)       -- the revision part of the local identifier
46
);
47
48
/*
49 6136 leinfelder
 * Replication changes to support DataONE System Metadata replication
50
 */
51
ALTER TABLE xml_replication ADD COLUMN systemmetadatareplicate NUMBER(1);
52
53 6542 leinfelder
/**
54
 * track the user-agent for the request
55
 */
56 6731 tao
ALTER TABLE access_log ADD COLUMN user_agent VARCHAR2(512);
57 6542 leinfelder
58 6136 leinfelder
/*
59 6012 leinfelder
 * add the nodedatadate column to xml_nodes
60
 * TODO: load the data into it (java?)
61
 */
62
ALTER TABLE xml_nodes ADD COLUMN nodedatadate TIMESTAMP;
63
ALTER TABLE xml_nodes_revisions ADD COLUMN nodedatadate TIMESTAMP;
64
ALTER TABLE xml_path_index ADD COLUMN nodedatadate TIMESTAMP;
65
CREATE INDEX xml_path_index_idx4 ON xml_path_index (nodedatadate);
66
67
/*
68 6658 leinfelder
 * Register the new schema
69 5400 jones
 */
70
INSERT INTO xml_catalog (entry_type, public_id, system_id)
71 5709 leinfelder
  VALUES ('Schema', '@eml2_1_1namespace@', '/schema/eml-2.1.1/eml.xsd');
72
73 6761 leinfelder
/**
74
 * Generate GUIDs for docid.rev
75
 */
76
INSERT INTO identifier (docid, rev, guid)
77
	SELECT docid, rev, docid || '.' || rev FROM xml_documents;
78
INSERT INTO identifier (docid, rev, guid)
79
	SELECT docid, revisionid, docid || '.' || revisionid FROM xml_revisions;
80
81 5400 jones
/*
82 6761 leinfelder
 *  Allow guid in xml_access table (for system metadata)
83
*/
84
ALTER TABLE xml_access ADD COLUMN guid VARCHAR2(2000);
85
86
/**
87
 * Upgrade xml_access records to use GUID from identifier table
88
 * NOTE: This duplicates existing access rules for every revision of a document
89
 */
90
INSERT INTO xml_access (
91
	guid, principal_name, permission, perm_type, perm_order,
92
	docid, accessfileid, begin_time, end_time, ticket_count, subtreeid, startnodeid, endnodeid
93
)
94
	SELECT
95
		id.guid, xa.principal_name, xa.permission, xa.perm_type, xa.perm_order,
96
		xa.docid, xa.accessfileid, xa.begin_time, xa.end_time, xa.ticket_count, xa.subtreeid, xa.startnodeid, xa.endnodeid
97
	FROM identifier id, xml_access xa
98
	WHERE id.docid = xa.docid;
99
100
/**
101
 * Include inline data access rows -- they have a special guid: 'scope.docid.rev.index'
102
 */
103
INSERT INTO xml_access (
104
	guid, principal_name, permission, perm_type, perm_order,
105
	docid, accessfileid, begin_time, end_time, ticket_count, subtreeid, startnodeid, endnodeid
106
)
107
	SELECT
108
		docid, principal_name, permission, perm_type, perm_order,
109
		docid, accessfileid, begin_time, end_time, ticket_count, subtreeid, startnodeid, endnodeid
110
	FROM xml_access
111
	WHERE docid like '%.%.%.%';
112
113
/**
114
 * Update the accessfileid to use guid
115
 * NOTE: uses the last revision's guid as the new accessfileid
116
 */
117
UPDATE xml_access
118
SET accessfileid = id.guid
119
FROM identifier id, xml_access xa
120
WHERE xa.accessfileid = id.docid
121
AND id.rev =
122 6764 leinfelder
	(SELECT MAX(id2.rev) FROM identifier id2 WHERE id.docid = id2.docid);
123 6761 leinfelder
124
/**
125
 * Remove old access rules
126
 */
127
DELETE FROM xml_access WHERE guid is null;
128
129
/**
130
 * clean up the xml_access table
131
 */
132
ALTER TABLE xml_access DROP COLUMN docid;
133
134
135
/*
136 5276 jones
 * update the database version
137
 */
138
UPDATE db_version SET status=0;
139
140
INSERT INTO db_version (version, status, date_created)
141 6550 leinfelder
  VALUES ('2.0.0', 1, CURRENT_DATE);