CREATE TABLE systemMetadata (
   guid   VARCHAR2(2000),    -- the globally unique string identifier
   docid  VARCHAR(250), 	 -- the local document id #
   rev    NUMBER(8),          -- the revision part of the local identifier
   date_uploaded DATE, -- the date/time the document was first submitted
   rights_holder VARCHAR2(250), --the user who has rights to the document, usually the first persons to upload it
   checksum VARCHAR2(512), --the checksum of the doc using the given algorithm (see below)
   checksum_algorithm VARCHAR2(250), --the algorithm used to calculate the checksum
   origin_member_node VARCHAR2(250), --the member node where the document was first uploaded
   authoritive_member_node VARCHAR2(250), --the member node that currently controls the document
   date_modified DATE, -- the last date/time that the file was changed
   submitter VARCHAR2(256), -- the user who originally submitted the doc
   object_format VARCHAR2(256), --the format of the object
   size VARCHAR2(256) --the size of the object
)

CREATE TABLE identifier (
   guid   VARCHAR2(2000), -- the globally unique string identifier
   docid  VARCHAR2(250),  -- the local document id #
   rev    NUMBER(8)       -- the revision part of the local identifier
);

/*
 * add the nodedatadate column to xml_nodes 
 * TODO: load the data into it (java?)
 */
ALTER TABLE xml_nodes ADD COLUMN nodedatadate TIMESTAMP;
ALTER TABLE xml_nodes_revisions ADD COLUMN nodedatadate TIMESTAMP;
ALTER TABLE xml_path_index ADD COLUMN nodedatadate TIMESTAMP;
CREATE INDEX xml_path_index_idx4 ON xml_path_index (nodedatadate);


/*
 * Register the DataONE schemas
 */
INSERT INTO xml_catalog (entry_type, public_id, system_id)
  VALUES ('Schema', 'http://dataone.org/service/types/0.5.1', '/schema/D1_SCHEMA_0_5_1/dataoneTypes.xsd');
INSERT INTO xml_catalog (entry_type, public_id, system_id)
  VALUES ('Schema', 'http://ns.dataone.org/service/types/0.6.1', '/schema/D1_SCHEMA_0_6_1/dataoneTypes.xsd');
INSERT INTO xml_catalog (entry_type, public_id, system_id)
  VALUES ('Schema', 'http://ns.dataone.org/service/types/0.6.2', '/schema/D1_SCHEMA_0_6_2/dataoneTypes.xsd');
  
INSERT INTO xml_catalog (entry_type, public_id, system_id)
  VALUES ('Schema', '@eml2_1_1namespace@', '/schema/eml-2.1.1/eml.xsd');

/*
 * update the database version
 */
UPDATE db_version SET status=0;

INSERT INTO db_version (version, status, date_created) 
  VALUES ('1.10.0', 1, CURRENT_DATE);
