1 |
2099
|
jones
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2004 Regents of the University of California and the
|
4 |
|
|
* National Center for Ecological Analysis and Synthesis
|
5 |
2
|
jones
|
*
|
6 |
2099
|
jones
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
8 |
|
|
* '$Revision$'
|
9 |
2
|
jones
|
*
|
10 |
2099
|
jones
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
2
|
jones
|
*/
|
24 |
|
|
|
25 |
5
|
jones
|
/*
|
26 |
19
|
jones
|
* Drop all of the objects in proper order
|
27 |
2
|
jones
|
*/
|
28 |
72
|
bojilova
|
set echo off
|
29 |
|
|
|
30 |
20
|
jones
|
DROP SEQUENCE xml_nodes_id_seq;
|
31 |
203
|
jones
|
DROP SEQUENCE xml_revisions_id_seq;
|
32 |
123
|
jones
|
DROP SEQUENCE xml_catalog_id_seq;
|
33 |
472
|
berkley
|
DROP SEQUENCE xml_relation_id_seq;
|
34 |
517
|
berkley
|
DROP SEQUENCE xml_replication_id_seq;
|
35 |
616
|
bojilova
|
DROP SEQUENCE accnum_uniqueid_seq;
|
36 |
749
|
bojilova
|
DROP SEQUENCE xml_documents_id_seq;
|
37 |
759
|
bojilova
|
DROP SEQUENCE accession_number_id_seq;
|
38 |
2099
|
jones
|
DROP SEQUENCE access_log_seq;
|
39 |
759
|
bojilova
|
|
40 |
|
|
/* Drop triggers are not necessary */
|
41 |
|
|
DROP TRIGGER xml_nodes_before_insert;
|
42 |
203
|
jones
|
DROP TRIGGER xml_revisions_before_insert;
|
43 |
93
|
bojilova
|
DROP TRIGGER xml_catalog_before_insert;
|
44 |
472
|
berkley
|
DROP TRIGGER xml_relation_before_insert;
|
45 |
517
|
berkley
|
DROP TRIGGER xml_replication_before_insert;
|
46 |
759
|
bojilova
|
DROP TRIGGER accession_number_before_insert;
|
47 |
2099
|
jones
|
DROP TRIGGER access_log_before_insert;
|
48 |
72
|
bojilova
|
|
49 |
123
|
jones
|
DROP TABLE xml_index;
|
50 |
414
|
bojilova
|
DROP TABLE xml_access;
|
51 |
1589
|
tao
|
DROP TABLE xml_accesssubtree;
|
52 |
414
|
bojilova
|
DROP TABLE xml_revisions;
|
53 |
689
|
bojilova
|
DROP TABLE xml_relation;
|
54 |
5
|
jones
|
DROP TABLE xml_documents;
|
55 |
20
|
jones
|
DROP TABLE xml_nodes;
|
56 |
517
|
berkley
|
DROP TABLE xml_replication;
|
57 |
698
|
bojilova
|
DROP TABLE xml_catalog;
|
58 |
759
|
bojilova
|
DROP TABLE accession_number;
|
59 |
2099
|
jones
|
DROP TABLE access_log;
|
60 |
3
|
jones
|
|
61 |
517
|
berkley
|
/*
|
62 |
|
|
*Replication -- table to store servers that metacat is replicated to
|
63 |
|
|
*/
|
64 |
|
|
CREATE TABLE xml_replication (
|
65 |
544
|
berkley
|
serverid NUMBER(20),
|
66 |
|
|
server VARCHAR2(512),
|
67 |
|
|
last_checked DATE,
|
68 |
1292
|
tao
|
replicate NUMBER(1),
|
69 |
|
|
datareplicate NUMBER(1),
|
70 |
|
|
hub NUMBER(1),
|
71 |
544
|
berkley
|
CONSTRAINT xml_replication_pk PRIMARY KEY (serverid)
|
72 |
|
|
);
|
73 |
|
|
|
74 |
|
|
CREATE SEQUENCE xml_replication_id_seq;
|
75 |
|
|
CREATE TRIGGER xml_replication_before_insert
|
76 |
|
|
BEFORE INSERT ON xml_replication FOR EACH ROW
|
77 |
|
|
BEGIN
|
78 |
|
|
SELECT xml_replication_id_seq.nextval
|
79 |
|
|
INTO :new.serverid
|
80 |
|
|
FROM dual;
|
81 |
|
|
END;
|
82 |
|
|
/
|
83 |
517
|
berkley
|
|
84 |
1292
|
tao
|
INSERT INTO xml_replication (server, replicate, datareplicate, hub)
|
85 |
|
|
VALUES ('localhost', '0', '0', '0');
|
86 |
550
|
berkley
|
|
87 |
3
|
jones
|
/*
|
88 |
20
|
jones
|
* Nodes -- table to store XML Nodes (both elements and attributes)
|
89 |
3
|
jones
|
*/
|
90 |
759
|
bojilova
|
CREATE SEQUENCE xml_nodes_id_seq;
|
91 |
20
|
jones
|
CREATE TABLE xml_nodes (
|
92 |
123
|
jones
|
nodeid NUMBER(20), -- the unique node id (pk)
|
93 |
|
|
nodeindex NUMBER(10), -- order of nodes within parent
|
94 |
|
|
nodetype VARCHAR2(20), -- type (DOCUMENT, COMMENT, PI,
|
95 |
|
|
-- ELEMENT, ATTRIBUTE, TEXT)
|
96 |
|
|
nodename VARCHAR2(250), -- the name of an element or attribute
|
97 |
825
|
bojilova
|
nodeprefix VARCHAR2(50), -- the namespace prefix of an element
|
98 |
|
|
-- or attribute
|
99 |
123
|
jones
|
nodedata VARCHAR2(4000), -- the data for this node (e.g.,
|
100 |
|
|
-- for TEXT it is the content)
|
101 |
|
|
parentnodeid NUMBER(20), -- index of the parent of this node
|
102 |
|
|
rootnodeid NUMBER(20), -- index of the root node of this tree
|
103 |
317
|
bojilova
|
docid VARCHAR2(250), -- index to the document id
|
104 |
3
|
jones
|
date_created DATE,
|
105 |
|
|
date_updated DATE,
|
106 |
20
|
jones
|
CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
|
107 |
123
|
jones
|
CONSTRAINT xml_nodes_root_fk
|
108 |
|
|
FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
|
109 |
20
|
jones
|
CONSTRAINT xml_nodes_parent_fk
|
110 |
|
|
FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
|
111 |
3
|
jones
|
);
|
112 |
759
|
bojilova
|
CREATE TRIGGER xml_nodes_before_insert
|
113 |
|
|
BEFORE INSERT ON xml_nodes FOR EACH ROW
|
114 |
|
|
BEGIN
|
115 |
|
|
SELECT xml_nodes_id_seq.nextval
|
116 |
|
|
INTO :new.nodeid
|
117 |
|
|
FROM dual;
|
118 |
|
|
END;
|
119 |
|
|
/
|
120 |
|
|
|
121 |
440
|
bojilova
|
/*
|
122 |
759
|
bojilova
|
* Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes
|
123 |
440
|
bojilova
|
*/
|
124 |
|
|
CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
|
125 |
|
|
CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
|
126 |
755
|
bojilova
|
CREATE INDEX xml_nodes_idx3 ON xml_nodes (nodename);
|
127 |
440
|
bojilova
|
|
128 |
3
|
jones
|
/*
|
129 |
698
|
bojilova
|
* XML Catalog -- table to store all external sources for XML documents
|
130 |
|
|
*/
|
131 |
|
|
CREATE TABLE xml_catalog (
|
132 |
|
|
catalog_id NUMBER(20), -- the id for this catalog entry
|
133 |
|
|
entry_type VARCHAR2(500), -- the type of this catalog entry
|
134 |
|
|
-- (e.g., DTD, XSD, XSL)
|
135 |
|
|
source_doctype VARCHAR2(500), -- the source public_id for transforms
|
136 |
|
|
target_doctype VARCHAR2(500), -- the target public_id for transforms
|
137 |
|
|
public_id VARCHAR2(500), -- the unique id for this type
|
138 |
|
|
system_id VARCHAR2(1000), -- the local location of the object
|
139 |
|
|
CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id),
|
140 |
|
|
CONSTRAINT xml_catalog_uk UNIQUE
|
141 |
|
|
(entry_type, source_doctype, target_doctype, public_id)
|
142 |
|
|
);
|
143 |
|
|
|
144 |
|
|
CREATE SEQUENCE xml_catalog_id_seq;
|
145 |
|
|
|
146 |
|
|
CREATE TRIGGER xml_catalog_before_insert
|
147 |
|
|
BEFORE INSERT ON xml_catalog FOR EACH ROW
|
148 |
|
|
BEGIN
|
149 |
|
|
SELECT xml_catalog_id_seq.nextval
|
150 |
|
|
INTO :new.catalog_id
|
151 |
|
|
FROM dual;
|
152 |
|
|
END;
|
153 |
|
|
/
|
154 |
|
|
|
155 |
|
|
/*
|
156 |
72
|
bojilova
|
* Documents -- table to store XML documents
|
157 |
5
|
jones
|
*/
|
158 |
|
|
CREATE TABLE xml_documents (
|
159 |
165
|
jones
|
docid VARCHAR2(250), -- the document id #
|
160 |
|
|
rootnodeid NUMBER(20), -- reference to root node of the DOM
|
161 |
123
|
jones
|
docname VARCHAR2(100), -- usually the root element name
|
162 |
|
|
doctype VARCHAR2(100), -- public id indicating document type
|
163 |
414
|
bojilova
|
user_owner VARCHAR2(100), -- the user owned the document
|
164 |
|
|
user_updated VARCHAR2(100), -- the user updated the document
|
165 |
825
|
bojilova
|
server_location NUMBER(20), -- the server on which this document
|
166 |
843
|
berkley
|
-- originates
|
167 |
825
|
bojilova
|
rev NUMBER(10) DEFAULT 1,--the revision number of the docume
|
168 |
5
|
jones
|
date_created DATE,
|
169 |
|
|
date_updated DATE,
|
170 |
698
|
bojilova
|
public_access NUMBER(1), -- flag for public access
|
171 |
|
|
catalog_id NUMBER(20), -- reference to xml_catalog
|
172 |
5
|
jones
|
CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
|
173 |
544
|
berkley
|
CONSTRAINT xml_documents_rep_fk
|
174 |
689
|
bojilova
|
FOREIGN KEY (server_location) REFERENCES xml_replication,
|
175 |
5
|
jones
|
CONSTRAINT xml_documents_root_fk
|
176 |
698
|
bojilova
|
FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
|
177 |
|
|
CONSTRAINT xml_documents_catalog_fk
|
178 |
|
|
FOREIGN KEY (catalog_id) REFERENCES xml_catalog
|
179 |
5
|
jones
|
);
|
180 |
|
|
|
181 |
72
|
bojilova
|
/*
|
182 |
440
|
bojilova
|
* Index of <docid,doctype> in xml_document
|
183 |
|
|
*/
|
184 |
|
|
CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
|
185 |
|
|
|
186 |
|
|
/*
|
187 |
203
|
jones
|
* Revised Documents -- table to store XML documents saved after an UPDATE
|
188 |
|
|
* or DELETE
|
189 |
|
|
*/
|
190 |
|
|
CREATE TABLE xml_revisions (
|
191 |
|
|
revisionid NUMBER(20), -- the revision number we are saving
|
192 |
|
|
docid VARCHAR2(250), -- the document id #
|
193 |
|
|
rootnodeid NUMBER(20), -- reference to root node of the DOM
|
194 |
|
|
docname VARCHAR2(100), -- usually the root element name
|
195 |
|
|
doctype VARCHAR2(100), -- public id indicating document type
|
196 |
414
|
bojilova
|
user_owner VARCHAR2(100),
|
197 |
|
|
user_updated VARCHAR2(100),
|
198 |
556
|
bojilova
|
server_location NUMBER(20),
|
199 |
689
|
bojilova
|
rev NUMBER(10),
|
200 |
203
|
jones
|
date_created DATE,
|
201 |
|
|
date_updated DATE,
|
202 |
698
|
bojilova
|
public_access NUMBER(1), -- flag for public access
|
203 |
|
|
catalog_id NUMBER(20), -- reference to xml_catalog
|
204 |
203
|
jones
|
CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
|
205 |
552
|
berkley
|
CONSTRAINT xml_revisions_rep_fk
|
206 |
689
|
bojilova
|
FOREIGN KEY (server_location) REFERENCES xml_replication,
|
207 |
203
|
jones
|
CONSTRAINT xml_revisions_root_fk
|
208 |
698
|
bojilova
|
FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
|
209 |
|
|
CONSTRAINT xml_revisions_catalog_fk
|
210 |
|
|
FOREIGN KEY (catalog_id) REFERENCES xml_catalog
|
211 |
203
|
jones
|
);
|
212 |
|
|
|
213 |
|
|
CREATE SEQUENCE xml_revisions_id_seq;
|
214 |
|
|
|
215 |
|
|
CREATE TRIGGER xml_revisions_before_insert
|
216 |
|
|
BEFORE INSERT ON xml_revisions FOR EACH ROW
|
217 |
|
|
BEGIN
|
218 |
|
|
SELECT xml_revisions_id_seq.nextval
|
219 |
|
|
INTO :new.revisionid
|
220 |
|
|
FROM dual;
|
221 |
|
|
END;
|
222 |
|
|
/
|
223 |
|
|
|
224 |
|
|
/*
|
225 |
698
|
bojilova
|
* ACL -- table to store ACL for XML documents by principals
|
226 |
72
|
bojilova
|
*/
|
227 |
698
|
bojilova
|
CREATE TABLE xml_access (
|
228 |
|
|
docid VARCHAR2(250), -- the document id #
|
229 |
|
|
accessfileid VARCHAR2(250), -- the document id # for the access file
|
230 |
|
|
principal_name VARCHAR2(100), -- name of user, group, etc.
|
231 |
|
|
permission NUMBER(1), -- "read", "write", "all"
|
232 |
|
|
perm_type VARCHAR2(32), -- "allowed" or "denied"
|
233 |
|
|
perm_order VARCHAR2(32), -- "allow first" or "deny first"
|
234 |
|
|
begin_time DATE, -- the time that permission begins
|
235 |
|
|
end_time DATE, -- the time that permission ends
|
236 |
|
|
ticket_count NUMBER(5), -- ticket counter for that permission
|
237 |
1420
|
tao
|
subtreeid VARCHAR2(32), -- sub tree id
|
238 |
|
|
startnodeid NUMBER(20), -- start node for sub tree
|
239 |
|
|
endnodeid NUMBER(20), -- end node for sub tree
|
240 |
698
|
bojilova
|
CONSTRAINT xml_access_ck CHECK (begin_time < end_time),
|
241 |
|
|
CONSTRAINT xml_access_accessfileid_fk
|
242 |
|
|
FOREIGN KEY (accessfileid) REFERENCES xml_documents
|
243 |
72
|
bojilova
|
);
|
244 |
|
|
|
245 |
123
|
jones
|
/*
|
246 |
|
|
* Index of Nodes -- table to store precomputed paths through tree for
|
247 |
|
|
* quick searching in structured searches
|
248 |
|
|
*/
|
249 |
|
|
CREATE TABLE xml_index (
|
250 |
|
|
nodeid NUMBER(20), -- the unique node id
|
251 |
177
|
jones
|
path VARCHAR2(200), -- precomputed path through tree
|
252 |
317
|
bojilova
|
docid VARCHAR2(250), -- index to the document id
|
253 |
|
|
doctype VARCHAR2(100), -- public id indicating document type
|
254 |
825
|
bojilova
|
parentnodeid NUMBER(20), -- id of the parent of the node
|
255 |
|
|
-- represented by this row
|
256 |
123
|
jones
|
CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
|
257 |
317
|
bojilova
|
CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
|
258 |
|
|
CONSTRAINT xml_index_docid_fk
|
259 |
|
|
FOREIGN KEY (docid) REFERENCES xml_documents
|
260 |
123
|
jones
|
);
|
261 |
163
|
bojilova
|
|
262 |
|
|
/*
|
263 |
177
|
jones
|
* Index of the paths in xml_index
|
264 |
|
|
*/
|
265 |
|
|
CREATE INDEX xml_index_idx1 ON xml_index (path);
|
266 |
|
|
|
267 |
472
|
berkley
|
CREATE TABLE xml_relation (
|
268 |
689
|
bojilova
|
relationid NUMBER(20) PRIMARY KEY, -- unique id
|
269 |
743
|
jones
|
docid VARCHAR2(250), -- the docid of the package file
|
270 |
689
|
bojilova
|
-- that this relation came from
|
271 |
743
|
jones
|
packagetype VARCHAR2(250), -- the type of the package
|
272 |
689
|
bojilova
|
subject VARCHAR2(512) NOT NULL, -- the subject of the relation
|
273 |
743
|
jones
|
subdoctype VARCHAR2(128), -- the doctype of the subject
|
274 |
689
|
bojilova
|
relationship VARCHAR2(128) NOT NULL,-- the relationship type
|
275 |
|
|
object VARCHAR2(512) NOT NULL, -- the object of the relation
|
276 |
|
|
objdoctype VARCHAR2(128), -- the doctype of the object
|
277 |
1604
|
tao
|
CONSTRAINT xml_relation_uk UNIQUE (docid, subject, relationship, object),
|
278 |
689
|
bojilova
|
CONSTRAINT xml_relation_docid_fk
|
279 |
|
|
FOREIGN KEY (docid) REFERENCES xml_documents
|
280 |
472
|
berkley
|
);
|
281 |
|
|
|
282 |
|
|
CREATE SEQUENCE xml_relation_id_seq;
|
283 |
|
|
|
284 |
|
|
CREATE TRIGGER xml_relation_before_insert
|
285 |
|
|
BEFORE INSERT ON xml_relation FOR EACH ROW
|
286 |
|
|
BEGIN
|
287 |
|
|
SELECT xml_relation_id_seq.nextval
|
288 |
|
|
INTO :new.relationid
|
289 |
|
|
FROM dual;
|
290 |
759
|
bojilova
|
END;
|
291 |
472
|
berkley
|
/
|
292 |
|
|
|
293 |
759
|
bojilova
|
/*
|
294 |
|
|
* Table used as Unique ID generator for the uniqueid part of Accession#
|
295 |
|
|
*/
|
296 |
|
|
CREATE SEQUENCE accession_number_id_seq;
|
297 |
|
|
CREATE TABLE accession_number (
|
298 |
|
|
uniqueid NUMBER(20) PRIMARY KEY,
|
299 |
|
|
site_code VARCHAR2(100),
|
300 |
|
|
date_created DATE
|
301 |
|
|
);
|
302 |
|
|
CREATE TRIGGER accession_number_before_insert
|
303 |
|
|
BEFORE INSERT ON accession_number FOR EACH ROW
|
304 |
|
|
BEGIN
|
305 |
|
|
SELECT accession_number_id_seq.nextval
|
306 |
|
|
INTO :new.uniqueid
|
307 |
|
|
FROM dual;
|
308 |
|
|
END;
|
309 |
|
|
/
|
310 |
|
|
|
311 |
1530
|
tao
|
/*
|
312 |
1589
|
tao
|
* accesssubtree -- table to store access subtree info
|
313 |
1530
|
tao
|
*/
|
314 |
|
|
CREATE TABLE xml_accesssubtree (
|
315 |
|
|
docid VARCHAR2(250), -- the document id #
|
316 |
|
|
rev NUMBER(10) DEFAULT 1, --the revision number of the docume
|
317 |
|
|
controllevel VARCHAR2(50), -- the level it control -- document or subtree
|
318 |
|
|
subtreeid VARCHAR2(250), -- the subtree id
|
319 |
|
|
startnodeid NUMBER(20), -- the start node id of access subtree
|
320 |
1625
|
tao
|
endnodeid NUMBER(20), -- the end node if of access subtree
|
321 |
|
|
CONSTRAINT xml_accesssubtree_docid_fk
|
322 |
|
|
FOREIGN KEY (docid) REFERENCES xml_documents
|
323 |
1530
|
tao
|
);
|
324 |
|
|
|
325 |
2099
|
jones
|
/*
|
326 |
|
|
* Logging -- table to store metadata and data access log
|
327 |
|
|
*/
|
328 |
|
|
CREATE TABLE access_log (
|
329 |
|
|
entryid NUMBER(20), -- the identifier for the log event
|
330 |
|
|
ip_address VARCHAR2(512), -- the ip address inititiating the event
|
331 |
|
|
principal VARCHAR2(512), -- the user initiiating the event
|
332 |
|
|
docid VARCHAR2(250), -- the document id #
|
333 |
|
|
event VARCHAR2(512), -- the code symbolizing the event type
|
334 |
|
|
date_logged DATE, -- the datetime on which the event occurred
|
335 |
|
|
CONSTRAINT access_log_pk PRIMARY KEY (entryid)
|
336 |
|
|
);
|
337 |
|
|
|
338 |
|
|
CREATE SEQUENCE access_log_id_seq;
|
339 |
|
|
CREATE TRIGGER access_log_before_insert
|
340 |
|
|
BEFORE INSERT ON access_log FOR EACH ROW
|
341 |
|
|
BEGIN
|
342 |
|
|
SELECT access_log_id_seq.nextval
|
343 |
|
|
INTO :new.entryid
|
344 |
|
|
FROM dual;
|
345 |
|
|
END;
|