Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *             National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author: jones $'
7
 *     '$Date: 2010-03-16 00:33:37 -0700 (Tue, 16 Mar 2010) $'
8
 * '$Revision: 5276 $'
9
 *
10
 * 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
 */
24

    
25
/*
26
 * Drop all of the objects in proper order
27
 */
28
set echo off
29

    
30
DROP SEQUENCE xml_nodes_id_seq;
31
DROP SEQUENCE xml_revisions_id_seq;
32
DROP SEQUENCE xml_catalog_id_seq;
33
DROP SEQUENCE xml_relation_id_seq;
34
DROP SEQUENCE xml_replication_id_seq;
35
DROP SEQUENCE access_log_id_seq;
36
DROP SEQUENCE xml_returnfield_id_seq;
37
DROP SEQUENCE xml_queryresult_id_seq;
38
DROP SEQUENCE xml_path_index_id_seq;
39
DROP SEQUENCE db_version_id_seq;
40

    
41
/* Drop triggers are not necessary */
42
DROP TRIGGER xml_nodes_before_insert;
43
DROP TRIGGER xml_revisions_before_insert;
44
DROP TRIGGER xml_catalog_before_insert;
45
DROP TRIGGER xml_relation_before_insert;
46
DROP TRIGGER xml_replication_before_insert;
47
DROP TRIGGER access_log_before_insert;
48
DROP TRIGGER xml_returnfield_before_insert;
49
DROP TRIGGER xml_queryresult_before_insert;
50
DROP TRIGGER db_version_before_insert;
51

    
52

    
53
DROP TABLE xml_index;
54
DROP TABLE xml_access;
55
DROP TABLE xml_accesssubtree;
56
DROP TABLE xml_revisions;
57
DROP TABLE xml_relation;
58
DROP TABLE xml_documents CASCADE CONSTRAINTS;
59
DROP TABLE xml_nodes;
60
DROP TABLE xml_nodes_revisions;
61
DROP TABLE xml_replication;
62
DROP TABLE xml_catalog;
63
DROP TABLE identifier;
64
DROP TABLE access_log;
65
DROP TABLE harvest_site_schedule;
66
DROP TABLE harvest_detail_log;
67
DROP TABLE harvest_log;
68
DROP TABLE xml_queryresult;
69
DROP TABLE xml_returnfield;
70
DROP TABLE xml_path_index;
71
DROP TABLE db_version;
72

    
73
/*
74
 *Replication -- table to store servers that metacat is replicated to
75
 */
76
CREATE TABLE xml_replication (
77
  serverid      NUMBER(20),
78
  server        VARCHAR2(512),
79
  last_checked  DATE,
80
  replicate     NUMBER(1),
81
  datareplicate NUMBER(1),
82
  hub NUMBER(1),
83
  CONSTRAINT xml_replication_pk PRIMARY KEY (serverid)
84
);
85

    
86
CREATE SEQUENCE xml_replication_id_seq;
87
CREATE TRIGGER xml_replication_before_insert
88
BEFORE INSERT ON xml_replication FOR EACH ROW
89
BEGIN
90
  SELECT xml_replication_id_seq.nextval
91
    INTO :new.serverid
92
    FROM dual;
93
END;
94
/
95

    
96
INSERT INTO xml_replication (server, replicate, datareplicate, hub)
97
 VALUES ('localhost', '0', '0', '0');
98

    
99
/*
100
 * Nodes -- table to store XML Nodes (both elements and attributes)
101
 */
102
CREATE SEQUENCE xml_nodes_id_seq;
103
CREATE TABLE xml_nodes (
104
	nodeid		NUMBER(20),	-- the unique node id (pk)
105
	nodeindex	NUMBER(10),	-- order of nodes within parent
106
	nodetype	VARCHAR2(20),	-- type (DOCUMENT, COMMENT, PI,
107
					-- ELEMENT, ATTRIBUTE, TEXT)
108
	nodename	VARCHAR2(250),	-- the name of an element or attribute
109
	nodeprefix	VARCHAR2(50),	-- the namespace prefix of an element
110
                                        -- or attribute
111
	nodedata	VARCHAR2(4000), -- the data for this node (e.g.,
112
					-- for TEXT it is the content)
113
	parentnodeid	NUMBER(20),	-- index of the parent of this node
114
	rootnodeid	NUMBER(20),	-- index of the root node of this tree
115
	docid		VARCHAR2(250),	-- index to the document id
116
	date_created	DATE,
117
	date_updated	DATE,
118
	nodedatanumerical NUMBER,       -- the data for this node if
119
					-- it is a number
120
   CONSTRAINT xml_nodes_pk PRIMARY KEY (nodeid),
121
   CONSTRAINT xml_nodes_root_fk
122
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
123
   CONSTRAINT xml_nodes_parent_fk
124
		FOREIGN KEY (parentnodeid) REFERENCES xml_nodes
125
);
126
CREATE TRIGGER xml_nodes_before_insert
127
BEFORE INSERT ON xml_nodes FOR EACH ROW
128
BEGIN
129
  SELECT xml_nodes_id_seq.nextval
130
    INTO :new.nodeid
131
    FROM dual;
132
END;
133
/
134

    
135

    
136
/*
137
 * Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes
138
 */
139
CREATE INDEX xml_nodes_idx1 ON xml_nodes (rootnodeid);
140
CREATE INDEX xml_nodes_idx2 ON xml_nodes (parentnodeid);
141
CREATE INDEX xml_nodes_idx3 ON xml_nodes (nodename);
142
CREATE INDEX xml_nodes_idx4 ON xml_nodes (docid);
143

    
144

    
145
/*
146
 * xml_nodes_revisions -- table to store nodes from xml_nodes which are of old revisions and deleted document
147
 */
148

    
149
CREATE TABLE xml_nodes_revisions (
150
        nodeid          NUMBER(20),     -- the unique node id (pk)
151
        nodeindex       NUMBER(10),     -- order of nodes within parent
152
        nodetype        VARCHAR2(20),   -- type (DOCUMENT, COMMENT, PI,
153
                                        -- ELEMENT, ATTRIBUTE, TEXT)
154
        nodename        VARCHAR2(250),  -- the name of an element or attribute
155
        nodeprefix      VARCHAR2(50),   -- the namespace prefix of an element
156
                                        -- or attribute
157
        nodedata        VARCHAR2(4000), -- the data for this node (e.g.,
158
                                        -- for TEXT it is the content)
159
        parentnodeid    NUMBER(20),     -- index of the parent of this node
160
        rootnodeid      NUMBER(20),     -- index of the root node of this tree
161
        docid           VARCHAR2(250),  -- index to the document id
162
        date_created    DATE,
163
        date_updated    DATE,
164
        nodedatanumerical NUMBER,       -- the data for this node if
165
                                        -- it is a number
166
   CONSTRAINT xml_nodes_revisions_pk PRIMARY KEY (nodeid),
167
   CONSTRAINT xml_nodes_revisions_root_fk
168
                FOREIGN KEY (rootnodeid) REFERENCES xml_nodes_revisions,
169
   CONSTRAINT xml_nodes_revisions_parent_fk
170
                FOREIGN KEY (parentnodeid) REFERENCES xml_nodes_revisions
171
);
172

    
173

    
174
/*
175
 * Indexes of rootnodeid, parentnodeid, and nodename in xml_nodes_revision
176
 */
177
CREATE INDEX xml_nodes_revisions_idx1 ON xml_nodes_revisions (rootnodeid);
178
CREATE INDEX xml_nodes_revisions_idx2 ON xml_nodes_revisions (parentnodeid);
179
CREATE INDEX xml_nodes_revisions_idx3 ON xml_nodes_revisions (nodename);
180

    
181
/*
182
 * XML Catalog -- table to store all external sources for XML documents
183
 */
184
CREATE TABLE xml_catalog (
185
	catalog_id	NUMBER(20),	-- the id for this catalog entry
186
	entry_type	VARCHAR2(500),	-- the type of this catalog entry
187
					-- (e.g., DTD, XSD, XSL)
188
	source_doctype	VARCHAR2(500),	-- the source public_id for transforms
189
	target_doctype	VARCHAR2(500),	-- the target public_id for transforms
190
	public_id	VARCHAR2(500),	-- the unique id for this type
191
	system_id	VARCHAR2(1000),	-- the local location of the object
192
   CONSTRAINT xml_catalog_pk PRIMARY KEY (catalog_id),
193
   CONSTRAINT xml_catalog_uk UNIQUE
194
		(entry_type, source_doctype, target_doctype, public_id)
195
);
196

    
197
CREATE SEQUENCE xml_catalog_id_seq;
198

    
199
CREATE TRIGGER xml_catalog_before_insert
200
BEFORE INSERT ON xml_catalog FOR EACH ROW
201
BEGIN
202
  SELECT xml_catalog_id_seq.nextval
203
    INTO :new.catalog_id
204
    FROM dual;
205
END;
206
/
207

    
208
/*
209
 * Documents -- table to store XML documents
210
 */
211
CREATE TABLE xml_documents (
212
	docid		VARCHAR2(250),	-- the document id #
213
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
214
	docname		VARCHAR2(100),	-- usually the root element name
215
	doctype		VARCHAR2(100),	-- public id indicating document type
216
	user_owner	VARCHAR2(100),	-- the user owned the document
217
	user_updated	VARCHAR2(100),	-- the user updated the document
218
	server_location NUMBER(20),	-- the server on which this document
219
                                        -- originates
220
	rev 		NUMBER(10) DEFAULT 1,--the revision number of the docume
221
	date_created	DATE,
222
	date_updated	DATE,
223
	public_access	NUMBER(1),	-- flag for public access
224
        catalog_id      NUMBER(20),	-- reference to xml_catalog
225
   CONSTRAINT xml_documents_pk PRIMARY KEY (docid),
226
   CONSTRAINT xml_documents_rep_fk
227
    		FOREIGN KEY (server_location) REFERENCES xml_replication,
228
   CONSTRAINT xml_documents_root_fk
229
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes,
230
   CONSTRAINT xml_documents_catalog_fk
231
		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
232
);
233

    
234
/*
235
 * Index of <docid,doctype> in xml_document
236
 */
237
CREATE INDEX xml_documents_idx1 ON xml_documents (docid, doctype);
238
CREATE INDEX xml_documents_idx2 ON xml_documents (lower(user_owner));
239
CREATE INDEX xml_documents_idx3 ON xml_documents (rootnodeid);
240

    
241
/*
242
 * Revised Documents -- table to store XML documents saved after an UPDATE
243
 *                    or DELETE
244
 */
245
CREATE TABLE xml_revisions (
246
	revisionid	NUMBER(20),	-- the revision number we are saving
247
	docid		VARCHAR2(250),	-- the document id #
248
	rootnodeid	NUMBER(20),	-- reference to root node of the DOM
249
	docname		VARCHAR2(100),	-- usually the root element name
250
	doctype		VARCHAR2(100),	-- public id indicating document type
251
	user_owner	VARCHAR2(100),
252
	user_updated	VARCHAR2(100),
253
	server_location NUMBER(20),
254
	rev		NUMBER(10),
255
	date_created	DATE,
256
	date_updated	DATE,
257
	public_access	NUMBER(1),	-- flag for public access
258
        catalog_id      NUMBER(20),	-- reference to xml_catalog
259
   CONSTRAINT xml_revisions_pk PRIMARY KEY (revisionid),
260
   CONSTRAINT xml_revisions_rep_fk
261
		FOREIGN KEY (server_location) REFERENCES xml_replication,
262
   CONSTRAINT xml_revisions_root_fk
263
		FOREIGN KEY (rootnodeid) REFERENCES xml_nodes_revisions,
264
   CONSTRAINT xml_revisions_catalog_fk
265
		FOREIGN KEY (catalog_id) REFERENCES xml_catalog
266
);
267

    
268
CREATE SEQUENCE xml_revisions_id_seq;
269

    
270
CREATE TRIGGER xml_revisions_before_insert
271
BEFORE INSERT ON xml_revisions FOR EACH ROW
272
BEGIN
273
  SELECT xml_revisions_id_seq.nextval
274
    INTO :new.revisionid
275
    FROM dual;
276
END;
277
/
278

    
279
/*
280
 * ACL -- table to store ACL for XML documents by principals
281
 */
282
CREATE TABLE xml_access (
283
	docid		VARCHAR2(250),	-- the document id #
284
	accessfileid	VARCHAR2(250),	-- the document id # for the access file
285
	principal_name	VARCHAR2(100),	-- name of user, group, etc.
286
	permission	NUMBER(1),	-- "read", "write", "all"
287
	perm_type	VARCHAR2(32),	-- "allowed" or "denied"
288
	perm_order	VARCHAR2(32),	-- "allow first" or "deny first"
289
	begin_time	DATE,		-- the time that permission begins
290
	end_time	DATE,		-- the time that permission ends
291
	ticket_count	NUMBER(5),	-- ticket counter for that permission
292
  subtreeid VARCHAR2(32), -- sub tree id
293
  startnodeid NUMBER(20), -- start node for sub tree
294
  endnodeid NUMBER(20),    -- end node for sub tree
295
   CONSTRAINT xml_access_ck CHECK (begin_time < end_time),
296
   CONSTRAINT xml_access_accessfileid_fk
297
		FOREIGN KEY (accessfileid) REFERENCES xml_documents
298
);
299
CREATE INDEX xml_access_idx1 ON xml_access (lower(principal_name));
300
CREATE INDEX xml_access_idx2 ON xml_access (permission);
301
CREATE INDEX xml_access_idx3 ON xml_access (perm_type);
302
CREATE INDEX xml_access_idx4 ON xml_access (perm_order);
303
CREATE INDEX xml_access_idx5 ON xml_access (subtreeid);
304

    
305

    
306
/*
307
 * Index of Nodes -- table to store precomputed paths through tree for
308
 * quick searching in structured searches
309
 */
310
CREATE TABLE xml_index (
311
	nodeid		NUMBER(20),	-- the unique node id
312
	path		VARCHAR2(1000),	-- precomputed path through tree
313
	docid		VARCHAR2(250),	-- index to the document id
314
	doctype		VARCHAR2(100),	-- public id indicating document type
315
        parentnodeid    NUMBER(20),     -- id of the parent of the node
316
					-- represented by this row
317
   CONSTRAINT xml_index_pk PRIMARY KEY (nodeid,path),
318
   CONSTRAINT xml_index_nodeid_fk FOREIGN KEY (nodeid) REFERENCES xml_nodes,
319
   CONSTRAINT xml_index_docid_fk
320
		FOREIGN KEY (docid) REFERENCES xml_documents
321
);
322

    
323
/*
324
 * Index of the paths in xml_index
325
 */
326
CREATE INDEX xml_index_idx1 ON xml_index (path);
327
CREATE INDEX xml_index_idx2 ON xml_index (docid);
328
CREATE INDEX xml_index_idx3 ON xml_index (nodeid);
329

    
330

    
331
/*
332
 * Index of Paths - table to store nodes with paths specified by userst in metacat.properties
333
 */
334
CREATE TABLE xml_path_index (
335
        nodeid          NUMBER(20),     -- the unique node id
336
        docid           VARCHAR2(250),  -- index to the document id
337
        path            VARCHAR2(1000), -- precomputed path through tree
338
	    nodedata        VARCHAR2(4000), -- the data for this node e.g.,
339
        nodedatanumerical NUMBER(20),   -- the data for this node if
340
        parentnodeid    NUMBER(20),     -- index of the parent of this node
341
        CONSTRAINT xml_path_index_pk PRIMARY KEY (nodeid),
342
        CONSTRAINT xml_path_index_docid_fk FOREIGN KEY (docid) REFERENCES xml_documents
343
 );                                                                                        
344

    
345

    
346
/*
347
 * create sequence an trigger
348
 */
349
CREATE SEQUENCE xml_path_index_id_seq;                                                                                                                                                             
350
CREATE TRIGGER xml_path_index_before_insert
351
BEFORE INSERT ON xml_path_index FOR EACH ROW
352
BEGIN
353
  SELECT xml_path_index_id_seq.nextval
354
    INTO :new.nodeid
355
    FROM dual;
356
END;
357
/
358

    
359

    
360
/*
361
 * Index of the path, nodedata, nodedatanumerical in xml_path_index
362
 */
363
CREATE INDEX xml_path_index_idx1 ON xml_path_index (path);
364
CREATE INDEX xml_path_index_idx2 ON xml_path_index (nodedata);
365
CREATE INDEX xml_path_index_idx3 ON xml_path_index (nodedatanumerical);
366

    
367

    
368

    
369
CREATE TABLE xml_relation (
370
	relationid    NUMBER(20) PRIMARY KEY, -- unique id
371
	docid         VARCHAR2(250),          -- the docid of the package file
372
	                                      -- that this relation came from
373
        packagetype   VARCHAR2(250),          -- the type of the package
374
	subject       VARCHAR2(512) NOT NULL, -- the subject of the relation
375
	subdoctype    VARCHAR2(128),          -- the doctype of the subject
376
	relationship  VARCHAR2(128)  NOT NULL,-- the relationship type
377
	object        VARCHAR2(512) NOT NULL, -- the object of the relation
378
	objdoctype    VARCHAR2(128),          -- the doctype of the object
379
	CONSTRAINT xml_relation_uk UNIQUE (docid, subject, relationship, object),
380
	CONSTRAINT xml_relation_docid_fk
381
		FOREIGN KEY (docid) REFERENCES xml_documents
382
  );
383

    
384
CREATE SEQUENCE xml_relation_id_seq;
385

    
386
CREATE TRIGGER xml_relation_before_insert
387
BEFORE INSERT ON xml_relation FOR EACH ROW
388
BEGIN
389
  SELECT xml_relation_id_seq.nextval
390
    INTO :new.relationid
391
    FROM dual;
392
END;
393
/
394

    
395
/*
396
 * Table used to store all document identifiers in metacat.  Each identifier
397
 * has a globally unique, unconstrained string, which we will refer to as a
398
 * GUID, and a local metacat identifier, which consists of the docid
399
 * and revision fields. Each row maps one global identifier to the local
400
 * identifier (docid) used within metacat.
401
 */
402
CREATE TABLE identifier (
403
   guid   VARCHAR2(2000), -- the globally unique string identifier
404
   docid  VARCHAR2(250),  -- the local document id #
405
   rev    NUMBER(8)       -- the revision part of the local identifier
406
);
407

    
408
/*
409
 * accesssubtree -- table to store access subtree info
410
 */
411
CREATE TABLE xml_accesssubtree (
412
	docid		VARCHAR2(250),	-- the document id #
413
  rev 		NUMBER(10) DEFAULT 1, --the revision number of the docume
414
  controllevel VARCHAR2(50), -- the level it control -- document or subtree
415
  subtreeid VARCHAR2(250), -- the subtree id
416
	startnodeid	NUMBER(20),	-- the start node id of access subtree
417
  endnodeid NUMBER(20), -- the end node if of access subtree
418
  CONSTRAINT xml_accesssubtree_docid_fk
419
		FOREIGN KEY (docid) REFERENCES xml_documents
420
);
421

    
422
/*
423
 * Returnfields -- table to store combinations of returnfields requested
424
 *		   and the number of times this table is accessed
425
 */
426
CREATE TABLE xml_returnfield (
427
        returnfield_id     NUMBER(20),     -- the id for this returnfield entry
428
        returnfield_string VARCHAR2(2000), -- the returnfield string
429
        usage_count        NUMBER(20),     -- the number of times this string
430
                                           -- has been requested
431
        CONSTRAINT xml_returnfield_pk PRIMARY KEY (returnfield_id)
432
);
433
CREATE INDEX xml_returnfield_idx1 ON xml_returnfield(returnfield_string);
434

    
435
CREATE SEQUENCE xml_returnfield_id_seq;
436

    
437
CREATE TRIGGER xml_returnfield_before_insert
438
BEFORE INSERT ON xml_returnfield FOR EACH ROW
439
BEGIN
440
  SELECT xml_returnfield_id_seq.nextval
441
    INTO :new.returnfield_id
442
    FROM dual;
443
END;
444
/
445

    
446
/*
447
 * Queryresults -- table to store queryresults for a given docid
448
 * and returnfield_id
449
 */
450
CREATE TABLE xml_queryresult(
451
  queryresult_id       NUMBER(20),     -- id for this entry
452
  returnfield_id       NUMBER(20),     -- id for the returnfield corresponding to this entry
453
  docid                VARCHAR2(250),  -- docid of the document
454
  queryresult_string   VARCHAR2(4000), -- resultant text generated for this docid and given
455
  				       -- returnfield
456
  CONSTRAINT xml_queryresult_pk PRIMARY KEY (queryresult_id),
457
  CONSTRAINT xml_queryresult_searchid_fk
458
               FOREIGN KEY (returnfield_id) REFERENCES xml_returnfield
459
);
460

    
461
CREATE INDEX xml_queryresult_idx1 ON xml_queryresult (returnfield_id, docid);
462

    
463
CREATE SEQUENCE xml_queryresult_id_seq;
464

    
465
CREATE TRIGGER xml_queryresult_before_insert
466
BEFORE INSERT ON xml_queryresult FOR EACH ROW
467
BEGIN
468
 SELECT xml_queryresult_id_seq.nextval
469
   INTO :new.queryresult_id
470
   FROM dual;
471
END;
472
/
473

    
474

    
475

    
476

    
477
/*
478
 * Logging -- table to store metadata and data access log
479
 */
480
CREATE TABLE access_log (
481
  entryid       NUMBER(20),     -- the identifier for the log event
482
  ip_address    VARCHAR2(512),  -- the ip address inititiating the event
483
  principal     VARCHAR2(512),  -- the user initiiating the event
484
  docid         VARCHAR2(250),	-- the document id #
485
  event         VARCHAR2(512),  -- the code symbolizing the event type
486
  date_logged   DATE,           -- the datetime on which the event occurred
487
  CONSTRAINT access_log_pk PRIMARY KEY (entryid)
488
);
489

    
490
CREATE SEQUENCE access_log_id_seq;
491
CREATE TRIGGER access_log_before_insert
492
BEFORE INSERT ON access_log FOR EACH ROW
493
BEGIN
494
  SELECT access_log_id_seq.nextval
495
    INTO :new.entryid
496
    FROM dual;
497
END;
498
/
499

    
500
/*
501
 * harvest_site_schedule -- table to store harvest sites and schedule info
502
 */
503
CREATE TABLE harvest_site_schedule (
504
  site_schedule_id NUMBER,         -- unique id
505
  documentlisturl  VARCHAR2(255),  -- URL of the site harvest document list
506
  ldapdn           VARCHAR2(255),  -- LDAP distinguished name for site account
507
  datenextharvest  DATE,           -- scheduled date of next harvest
508
  datelastharvest  DATE,           -- recorded date of last harvest
509
  updatefrequency  NUMBER,         -- the harvest update frequency
510
  unit             VARCHAR2(50),   -- update unit -- days weeks or months
511
  contact_email    VARCHAR2(50),   -- email address of the site contact person
512
  ldappwd          VARCHAR2(20),   -- LDAP password for site account
513
  CONSTRAINT harvest_site_schedule_pk PRIMARY KEY (site_schedule_id)
514
);
515

    
516
/*
517
 * harvest_log -- table to log entries for harvest operations
518
 */
519
CREATE TABLE harvest_log (
520
  harvest_log_id         NUMBER,         -- unique id
521
  harvest_date           DATE,           -- date of the current harvest
522
  status                 NUMBER,         -- non-zero indicates an error status
523
  message                VARCHAR2(1000), -- text message for this log entry
524
  harvest_operation_code VARCHAR2(30),   -- the type of harvest operation
525
  site_schedule_id       NUMBER,         -- site schedule id, or 0 if no site
526
  CONSTRAINT harvest_log_pk PRIMARY KEY (harvest_log_id)
527
);
528

    
529
/*
530
 * harvest_detail_log -- table to log detailed info about documents that
531
 *                       generated errors during the harvest
532
 */
533
CREATE TABLE harvest_detail_log (
534
  detail_log_id          NUMBER,         -- unique id
535
  harvest_log_id         NUMBER,         -- ponter to the related log entry
536
  scope                  VARCHAR2(50),   -- document scope
537
  identifier             NUMBER,         -- document identifier
538
  revision               NUMBER,         -- document revision
539
  document_url           VARCHAR2(255),  -- document URL
540
  error_message          VARCHAR2(1000), -- text error message
541
  document_type          VARCHAR2(100),  -- document type
542
  CONSTRAINT harvest_detail_log_pk PRIMARY KEY (detail_log_id),
543
  CONSTRAINT harvest_detail_log_fk
544
        FOREIGN KEY (harvest_log_id) REFERENCES harvest_log
545
);
546

    
547
/*
548
 * db_version -- table to store the version history of this database
549
 */
550
CREATE TABLE db_version (
551
  db_version_id   NUMBER(20),       -- the identifier for the version
552
  version         VARCHAR(250),     -- the version number
553
  status          NUMBER(20),       -- status of the version
554
  date_created    DATE,             -- the datetime on which the version was created
555
  CONSTRAINT db_version_pk PRIMARY KEY (db_version_id)
556
);
557

    
558
CREATE SEQUENCE db_version_id_seq;
559
CREATE TRIGGER db_version_before_insert
560
BEFORE INSERT ON db_version FOR EACH ROW
561
BEGIN
562
  SELECT db_version_id_seq.nextval
563
    INTO :new.db_version_id
564
    FROM dual;
565
END;
566
/
567

    
568
/*
569
 * scheduled_job -- table to store scheduled jobs
570
 */
571
CREATE TABLE scheduled_job (
572
  id NUMBER(20) NOT NULL default nextval('scheduled_job_id_seq'),
573
  date_created TIMESTAMP NOT NULL,
574
  date_updated TIMESTAMP NOT NULL,
575
  status VARCHAR2(64) NOT NULL,
576
  name VARCHAR2(512) NOT NULL,
577
  trigger_name VARCHAR2(512) NOT NULL,
578
  group_name VARCHAR2(512) NOT NULL,
579
  class_name VARCHAR2(1024) NOT NULL,
580
  start_time TIMESTAMP NOT NULL,
581
  interval_value NUMBER NOT NULL,
582
  interval_unit VARCHAR2(8) NOT NULL,
583
  CONSTRAINT scheduled_job_pk PRIMARY KEY (id),
584
  CONSTRAINT scheduled_job_uk UNIQUE (name)
585
);
586

    
587
CREATE SEQUENCE scheduled_job_id_seq;
588
CREATE TRIGGER scheduled_job_before_insert
589
BEFORE INSERT ON scheduled_job FOR EACH ROW
590
BEGIN
591
  SELECT scheduled_job_id_seq.nextval
592
    INTO :new.id
593
    FROM dual;
594
END;
595
/
596

    
597
/*
598
 * scheduled_job_params -- table to store scheduled job parameters
599
 */
600
CREATE TABLE scheduled_job_params (
601
  id NUMBER(20)  NOT NULL default nextval('scheduled_job_params_id_seq'),
602
  date_created TIMESTAMP NOT NULL,
603
  date_updated TIMESTAMP  NOT NULL,
604
  status VARCHAR2(64)  NOT NULL,
605
  job_id NUMBER(20) NOT NULL,
606
  key VARCHAR2(64) NOT NULL,
607
  value VARCHAR2(1024) NOT NULL,
608
  CONSTRAINT scheduled_job_params_pk PRIMARY KEY (id),
609
  CONSTRAINT scheduled_job_params_fk
610
        FOREIGN KEY (job_id) REFERENCES scheduled_job(id)
611
);
612

    
613
CREATE SEQUENCE scheduled_job_params_id_seq;
614
CREATE TRIGGER scheduled_job_params_before_insert
615
BEFORE INSERT ON scheduled_job_params FOR EACH ROW
616
BEGIN
617
  SELECT scheduled_job_id_params_seq.nextval
618
    INTO :new.id
619
    FROM dual;
620
END;
621
/
622

    
(46-46/48)