/*==============================================================*/
/* Table: DOCUMENTVIEWFIELDS                           			*/
/*==============================================================*/
create table DOCUMENTVIEWFIELDS (
FIELDID              INTEGER                        not null,
NAME            	 VARCHAR(256)                   not null,
NAMEKEY              VARCHAR(256)					not null,
DEFAULTFIELD         INTEGER						not null,

constraint PK_DOCUMENTVIEWFIELDS primary key ( FIELDID )
);

/*==============================================================*/
/* Table: USERDOCVIEWFIELDS                            			*/
/*==============================================================*/
create table USERDOCVIEWFIELDS (
ENTRYID              INTEGER                        not null,
FIELDID            	 INTEGER                        not null,
USERID               INTEGER					    not null,

constraint PK_USERDOCVIEWFIELDS primary key ( ENTRYID)
);

create unique asc index INDEX_30 on USERDOCVIEWFIELDS(
USERID, FIELDID);

alter table USERDOCVIEWFIELDS
    add constraint FK_USERDOVIEWFIELDS foreign key (USERID)
        references USERS(USERID);

alter table USERDOCVIEWFIELDS
    add constraint FK_USERDOVIEWFIELDS2 foreign key (FIELDID)
        references DOCUMENTVIEWFIELDS(FIELDID);

insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (1, 'fileName', 'vkc.document.type.file', 1);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (2, 'fileFormat', 'vkc.document.type.fileformat', 1);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (3, 'fileSize', 'vkc.document.type.filesize', 1);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (4, 'classType', 'vkc.document.class', 1);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (5, 'statusType', 'vkc.document.status', 1);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (6, 'versionNo', 'vkc.document.version', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (7, 'versionLabel', 'vkc.document.label', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (8, 'versionDescr', 'vkc.document.versiondescr', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (9, 'expires', 'vkc.document.expires', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (10, 'published', 'vkc.published', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (11, 'author', 'vkc.author', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (12, 'accessCount', 'vkc.accesscount', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (13, 'lastAccessed', 'vkc.lastaccessed', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (14, 'keywords', 'vkc.keywords', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (15, 'description', 'vkc.description', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (16, 'additionalFormats', 'vkc.document.additional_formats', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (17, 'dynaAttributes', '', 0);
insert into DOCUMENTVIEWFIELDS
            (FIELDID, NAME, NAMEKEY, DEFAULTFIELD)
     values (18, 'addAttributes', '', 0);

create generator DOCUMENTVIEWFIELDS_SEQ;
set generator DOCUMENTVIEWFIELDS_SEQ to 19;

create generator USERDOCVIEWFIELDS_SEQ;
set generator USERDOCVIEWFIELDS_SEQ to 1;

drop generator USERDOCVIEWCONFIG_SEQ;
drop table USERDOCVIEWCONFIG;

update SYSPARAMETERS set VALUESTRING = '1'  where CONTEXT = 'SYSTEMINFO' and name = 'DBVersionHigh';
update SYSPARAMETERS set VALUESTRING = '86' where CONTEXT = 'SYSTEMINFO' and name = 'DBVersionLow';
update SYSPARAMETERS set VALUESTRING = '2004-04-29' where CONTEXT = 'SYSTEMINFO' and name = 'DBCreationDate';

commit;