Project

General

Profile

1 741 harris
/*
2 755 bojilova
 * xmltables-postgres.sql
3
 *             : Create or replace tables for storing XML in PostgreSQL
4 741 harris
 *
5 755 bojilova
 *      Purpose: creates tables needed for storing XML in PostgreSQL database
6 741 harris
 *
7
 *      Created: 08 May 2001
8
 *       Author: John Harris
9
 * Organization: National Center for Ecological Analysis and Synthesis
10
 *    Copyright: 2000 Regents of the University of California and the
11
 *               National Center for Ecological Analysis and Synthesis
12 755 bojilova
 *  For Details: http://www.nceas.ucsb.edu/
13
 *    File Info: '$Id$'
14 741 harris
 *
15
 *	this is sql script does the same as the sql script named
16
 *	xmltables.sql except that this script is to be use to
17
 *	create the database tables on a Postgresql backend rather
18
 *	than an Oracle Backend
19
 */
20
21
/*
22
 * Drop all of the objects in proper order
23
 */
24
25
DROP SEQUENCE xml_nodes_id_seq;
26
DROP SEQUENCE xml_revisions_id_seq;
27
DROP SEQUENCE xml_catalog_id_seq;
28
DROP SEQUENCE xml_relation_id_seq;
29
DROP SEQUENCE xml_replication_id_seq;
30 749 bojilova
DROP SEQUENCE xml_documents_id_seq;
31 759 bojilova
DROP SEQUENCE accession_number_id_seq;
32 741 harris
33
DROP TABLE xml_index;
34
DROP TABLE xml_access;
35
DROP TABLE xml_revisions;
36
DROP TABLE xml_relation;
37
DROP TABLE xml_documents;
38
DROP TABLE xml_nodes;
39
DROP TABLE xml_replication;
40
DROP TABLE xml_catalog;
41 759 bojilova
DROP TABLE accession_number;
42 741 harris
43
/*
44
 *Replication -- table to store servers that metacat is replicated to
45
 */
46
CREATE SEQUENCE xml_replication_id_seq;
47
CREATE TABLE xml_replication (
48 898 berkley
  serverid INT8 default nextval('xml_replication_id_seq'),
49
  server VARCHAR(512),
50
  last_checked DATE,
51 1292 tao
  replicate INT8,
52
  datareplicate INT8,
53
  hub INT8,
54 741 harris
  CONSTRAINT xml_replication_pk PRIMARY KEY (serverid)
55
);
56
57 1292 tao
INSERT INTO xml_replication (server, replicate, datareplicate, hub) VALUES ('localhost', '0', '0', '0');
58 741 harris
59
/*
60
 * Nodes -- table to store XML Nodes (both elements and attributes)
61
 */
62 759 bojilova
CREATE SEQUENCE xml_nodes_id_seq;
63 741 harris
CREATE TABLE xml_nodes (
64 898 berkley
	nodeid INT8 default nextval('xml_nodes_id_seq'),
65 759 bojilova
					-- the unique node id (pk)
66 898 berkley
	nodeindex INT8,		-- order of nodes within parent
67
	nodetype VARCHAR(20),	-- type (DOCUMENT, COMMENT, PI,
68 741 harris
					-- ELEMENT, ATTRIBUTE, TEXT)
69 898 berkley
	nodename VARCHAR(250),	-- the name of an element or attribute
70
        nodeprefix VARCHAR(50), -- the namespace prefix of the node
71
	nodedata VARCHAR(4000), 	-- the data for this node (e.g.,
72 741 harris
					-- for TEXT it is the content)
73 898 berkley
	parentnodeid INT8,		-- index of the parent of this node
74
	rootnodeid INT8,		-- index of the root node of this tree
75
	docid VARCHAR(250),	-- index to the document id
76
	date_created DATE,
77
	date_updated DATE,
78 741 harris
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
79
   CONSTRAINT xml_nodes_root_fk
80
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
81
   CONSTRAINT xml_nodes_parent_fk
82
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
83
);
84
/*
85 759 bojilova
 * Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes
86 741 harris
 */
87
CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
88
CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
89 755 bojilova
CREATE INDEX xml_nodes_idx3 ON xml_nodes (nodename);
90 741 harris
91
/*
92
 * XML Catalog -- table to store all external sources for XML documents
93
 */
94
CREATE SEQUENCE xml_catalog_id_seq;
95
CREATE TABLE xml_catalog (
96 898 berkley
	catalog_id INT8 default nextval('xml_catalog_id_seq'),
97 759 bojilova
                                        -- the id for this catalog entry
98 898 berkley
	entry_type VARCHAR(500),	-- the type of this catalog entry
99 741 harris
					-- (e.g., DTD, XSD, XSL)
100 898 berkley
	source_doctype VARCHAR(500),	-- the source public_id for transforms
101
	target_doctype VARCHAR(500),	-- the target public_id for transforms
102
	public_id VARCHAR(500),	-- the unique id for this type
103
	system_id VARCHAR(1000),	-- the local location of the object
104 741 harris
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id),
105 759 bojilova
   CONSTRAINT xml_catalog_uk UNIQUE
106
              (entry_type, source_doctype, target_doctype, public_id)
107 741 harris
);
108
109
/*
110 749 bojilova
 * Sequence to get uniqueID for Accession #
111
 */
112
CREATE SEQUENCE xml_documents_id_seq;
113
/*
114 741 harris
 * Documents -- table to store XML documents
115
 */
116
CREATE TABLE xml_documents (
117 898 berkley
	docid VARCHAR(250),	-- the document id #
118
	rootnodeid INT8,		-- reference to root node of the DOM
119
	docname VARCHAR(100),	-- usually the root element name
120
	doctype VARCHAR(100),	-- public id indicating document type
121
	user_owner VARCHAR(100),	-- the user owned the document
122
	user_updated VARCHAR(100),	-- the user updated the document
123 741 harris
	server_location INT8,	-- the server on which this document resides
124 899 berkley
	rev INT8 default 1,   -- the revision number of the document
125 898 berkley
	date_created DATE,
126
	date_updated DATE,
127
	public_access INT8,	-- flag for public access
128
        catalog_id INT8,	-- reference to xml_catalog
129 741 harris
     CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
130
     CONSTRAINT xml_documents_rep_fk
131
     		FOREIGN KEY (server_location) REFERENCES xml_replication,
132
    CONSTRAINT xml_documents_root_fk
133
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
134
   CONSTRAINT xml_documents_catalog_fk
135
		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
136
);
137
138
/*
139
 * Index of <docid,doctype> in xml_document
140
 */
141
CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
142
143
/*
144
 * Revised Documents -- table to store XML documents saved after an UPDATE
145
 *                    or DELETE
146
 */
147
CREATE SEQUENCE xml_revisions_id_seq;
148
CREATE TABLE xml_revisions (
149 898 berkley
	revisionid INT8  default nextval('xml_revisions_id_seq'),
150 759 bojilova
                                        -- the revision number we are saving
151 898 berkley
	docid VARCHAR(250),	-- the document id #
152
	rootnodeid INT8,		-- reference to root node of the DOM
153
	docname VARCHAR(100),	-- usually the root element name
154
	doctype VARCHAR(100),	-- public id indicating document type
155
	user_owner VARCHAR(100),
156
	user_updated VARCHAR(100),
157 741 harris
	server_location INT8,
158 898 berkley
	rev INT8,
159
	date_created DATE,
160
	date_updated DATE,
161
	public_access INT8,	-- flag for public access
162
        catalog_id INT8,	-- reference to xml_catalog
163 741 harris
   CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
164
   CONSTRAINT xml_revisions_rep_fk
165
		FOREIGN KEY (server_location) REFERENCES xml_replication,
166
   CONSTRAINT xml_revisions_root_fk
167
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
168
   CONSTRAINT xml_revisions_catalog_fk
169
		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
170
);
171
172
173
/*
174
 * ACL -- table to store ACL for XML documents by principals
175
 */
176
CREATE TABLE xml_access (
177 898 berkley
	docid VARCHAR(250),	-- the document id #
178
	accessfileid VARCHAR(250),	-- the document id # for the access file
179
	principal_name VARCHAR(100),	-- name of user, group, etc.
180
	permission INT8,		-- "read", "write", "all"
181
	perm_type VARCHAR(32),	-- "allowed" or "denied"
182
	perm_order VARCHAR(32),	-- "allow first" or "deny first"
183
	begin_time DATE,		-- the time that permission begins
184
	end_time DATE,		-- the time that permission ends
185
	ticket_count INT8,		-- ticket counter for that permission
186 1421 tao
  subtreeid VARCHAR(32),
187
  startnodeid INT8,
188
  endnodeid INT8,
189 741 harris
   CONSTRAINT xml_access_ck CHECK (begin_time < end_time),
190
   CONSTRAINT xml_access_accessfileid_fk
191
		FOREIGN KEY (accessfileid) REFERENCES xml_documents
192
);
193
194
/*
195
 * Index of Nodes -- table to store precomputed paths through tree for
196
 * quick searching in structured searches
197
 */
198
CREATE TABLE xml_index (
199 898 berkley
	nodeid INT8,		-- the unique node id
200
	path VARCHAR(200),	-- precomputed path through tree
201
	docid VARCHAR(250),	-- index to the document id
202
	doctype VARCHAR(100),	-- public id indicating document type
203
        parentnodeid INT8,     -- id of the parent of the node represented
204 741 harris
					-- by this row
205
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
206
   CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
207
   CONSTRAINT xml_index_docid_fk
208
		FOREIGN KEY (docid) REFERENCES xml_documents
209
);
210
211
/*
212
 * Index of the paths in xml_index
213
 */
214
CREATE INDEX xml_index_idx1 ON xml_index (path);
215
216 749 bojilova
217 741 harris
CREATE SEQUENCE xml_relation_id_seq;
218
CREATE TABLE xml_relation (
219 898 berkley
	relationid INT8 default nextval('xml_relation_id_seq') PRIMARY KEY,
220 759 bojilova
					     -- unique id
221 898 berkley
	docid VARCHAR(250) ,         -- the docid of the package file
222 759 bojilova
	                                     -- that this relation came from
223 898 berkley
        packagetype VARCHAR(250),          -- the type of the package
224
	subject VARCHAR(512) NOT NULL, -- the subject of the relation
225
	subdoctype VARCHAR(128),         	-- the doctype of the subject
226
	relationship VARCHAR(128)  NOT NULL,-- the relationship type
227
	object VARCHAR(512) NOT NULL, -- the object of the relation
228
	objdoctype VARCHAR(128),          -- the doctype of the object
229 741 harris
	CONSTRAINT xml_relation_uk UNIQUE (subject, relationship, object),
230
	CONSTRAINT xml_relation_docid_fk
231
		FOREIGN KEY (docid) REFERENCES xml_documents
232 898 berkley
);
233 741 harris
234 759 bojilova
/*
235
 * Table used as Unique ID generator for the uniqueid part of Accession#
236
 */
237
CREATE SEQUENCE accession_number_id_seq;
238
CREATE TABLE accession_number (
239 898 berkley
   uniqueid INT8 default nextval('accession_number_id_seq') PRIMARY KEY,
240
   site_code VARCHAR(100),
241
   date_created DATE
242 759 bojilova
);
243 741 harris
244 759 bojilova