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

CREATE TABLE identifier (
   guid   text,          -- the globally unique string identifier
   docid  VARCHAR(250),  -- the local document id #
   rev    INT8,          -- the revision part of the local identifier
   CONSTRAINT identifier_pk PRIMARY KEY (guid)
);

/*
 * add the nodedatadate column to the tables that need it 
 */
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_idx5 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', '@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);

