------------------------------------------------------------------------------
--- Copyright (c) 1998-2009 Luna Imaging, Inc.  All Rights Reserved.
---
--- This software is confidential and proprietary information of
--- Luna Imaging, Inc.  ("Confidential Information").  You shall not
--- disclose such Confidential Information and shall use it only in
--- accordance with the terms of the license agreement you entered into
--- with Luna Imaging, Inc.
---
--- The software may not be copied, reproduced, translated or reduced to
--- any electronic medium or machine-readable form without
--- the prior written consent of Luna Imaging.
---
--- You are not allowed to distribute the binary and source code
--- (if released) to third parties, without the prior written consent from
--- Luna Imaging.
---
--- You are not allowed to reverse engineer, disassemble or decompile
--- code, or make any modifications of the binary or source code, remove
--- or alter any trademark, logo, copyright or other proprietary notices,
--- legends, symbols, or labels in the Software.
---
--- You are not allowed to sub-license the Software or any derivative
--- work based on or derived from the Software.
---
--- LUNA IMAGING MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
--- OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
--- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
--- PURPOSE, OR NON-INFRINGEMENT, LUNA IMAGING SHALL NOT BE LIABLE FOR ANY
--- DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
--- DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
------------------------------------------------------------------------------

------------------------------------------------
-- Create Table Statements for MEDIAFIELDRELATIONS
------------------------------------------------  

CREATE TABLE MEDIAFIELDRELATIONS(
    SOURCESTANDARDID VARCHAR2(50) NOT NULL,
    SOURCEFIELDNAME VARCHAR2(50) NOT NULL,
    DESTSTANDARDID NUMBER NOT NULL,
    DESTFIELDNAME VARCHAR2(50) NOT NULL );

ALTER TABLE MEDIAFIELDRELATIONS
  ADD CONSTRAINT PK_MEDIAFIELDRELATIONS
  PRIMARY KEY (SOURCESTANDARDID, SOURCEFIELDNAME, DESTSTANDARDID, DESTFIELDNAME);

------------------------------------------------
-- Create Table Statements for MEDIAFIELDSTANDARDS
------------------------------------------------  
 
CREATE TABLE MEDIAFIELDSTANDARDS(
    STANDARDID NUMBER NOT NULL,
    STANDARDNAME VARCHAR2(50) NULL);
    
ALTER TABLE MEDIAFIELDSTANDARDS
  ADD CONSTRAINT PK_MEDIAFIELDSTANDARDS
  PRIMARY KEY (STANDARDID);

------------------------------------------------
-- Create Table Statements for MEDIASTANDARDFIELDS
------------------------------------------------  
      
CREATE TABLE MEDIASTANDARDFIELDS(
    STANDARDFIELDID NUMBER NOT NULL,
    STANDARDFIELDNAME VARCHAR2(50),
    STANDARDFIELDDISPLAYORDER NUMBER NOT NULL,
    STANDARDID NUMBER NOT NULL);
    
ALTER TABLE MEDIASTANDARDFIELDS
  ADD CONSTRAINT PK_MEDIASTANDARDFIELDS
  PRIMARY KEY (STANDARDFIELDID, STANDARDID);


------------------------------------------------
-- Create Table Statements for TINYURLS
------------------------------------------------  

CREATE TABLE TINYURLS(
    ID NUMBER NOT NULL,
    TOKEN VARCHAR2(50) NOT NULL,
    MAPPEDURL VARCHAR2(4000) NOT NULL,
    CREATEDTIMESTAMP VARCHAR2(50) NOT NULL);

ALTER TABLE TINYURLS
  ADD CONSTRAINT PK_TINYURLS
  PRIMARY KEY(ID);

create sequence TINYURLS_seq 
  start with 1 
  increment by 1 
  nomaxvalue;  

-- Create Trigger TINYURLS_trigger
create trigger TINYURLS_trigger before insert on TINYURLS for each row when (new.id is null) begin select TINYURLS_seq.nextval into :new.id from dual; end;;


ALTER TABLE EXTERNALMEDIA MODIFY DISPLAYTITLE VARCHAR2(1000);

------------------------------------------------
-- Default Inserts for Standards
------------------------------------------------  

INSERT INTO MEDIAFIELDSTANDARDS ( STANDARDID, STANDARDNAME ) VALUES ( 1, 'DUBLIN CORE' );
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (1, 'TITLE', 1, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (2, 'CREATOR', 2, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (3, 'SUBJECT', 3, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (4, 'DESCRIPTION', 4, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (5, 'PUBLISHER', 5, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (6, 'CONTRIBUTOR', 6, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (7, 'DATE', 7, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (8, 'TYPE', 8, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (9, 'FORMAT', 9, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (10, 'IDENTIFIER', 10, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (11, 'SOURCE', 11, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (12, 'LANGUAGE', 12, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (13, 'RELATION', 13, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (14, 'COVERAGE', 14, 1);
INSERT INTO MEDIASTANDARDFIELDS ( STANDARDFIELDID, STANDARDFIELDNAME, STANDARDFIELDDISPLAYORDER, STANDARDID ) VALUES (15, 'RIGHTS', 15, 1);

INSERT INTO APPLICATIONCONFIGURATION(ATTRIBUTE,ATTRIBUTEVALUE)VALUES('rssEnabled','true');
INSERT INTO APPLICATIONCONFIGURATION(ATTRIBUTE,ATTRIBUTEVALUE)VALUES('linkSearchEnabled','true');
INSERT INTO APPLICATIONCONFIGURATION(ATTRIBUTE,ATTRIBUTEVALUE)VALUES('linkSearchExcludedFields','Collection, Image ID, Resolution Size, Format, Media Type, File Name, Width, Height, Originating Url');
INSERT INTO APPLICATIONCONFIGURATION(ATTRIBUTE,ATTRIBUTEVALUE)VALUES('linkSearchHideDelayMilliSec','1000');
INSERT INTO APPLICATIONCONFIGURATION(ATTRIBUTE,ATTRIBUTEVALUE)VALUES('linkSearchShowDelayMilliSec','50');

commit;