update SYSPARAMETERS set VALUESTRING = '1'  where CONTEXT = 'SYSTEMINFO' and name = 'DBVersionHigh'
/

update SYSPARAMETERS set VALUESTRING = '187' where CONTEXT = 'SYSTEMINFO' and name = 'DBVersionLow'
/

update SYSPARAMETERS set VALUESTRING = '2007-03-01' where CONTEXT = 'SYSTEMINFO' and name = 'DBCreationDate'
/

create table NOTES(
	noteId INTEGER NOT NULL,
	objectId INTEGER,
	sourceTable varchar(255),
	successorId INTEGER,
	text varchar(4000),
CONSTRAINT PK_NOTES PRIMARY KEY (noteId)
)
/

create sequence NOTES_SEQ start with 2 increment by 1
/

insert into NOTES(noteId,objectId,text) select NOTES_SEQ.NEXTVAL, documentId, description from Documents WHERE Description is not null 
/

update NOTES set sourceTable='DOCUMENTS' where sourceTable is null
/

insert into NOTES(noteId,objectId,text) select  NOTES_SEQ.NEXTVAL, categoryId, description from Categories WHERE Description is not null 
/

update NOTES set sourceTable='CATEGORIES' where sourceTable is null
/

insert into NOTES(noteId,objectId,text) select  NOTES_SEQ.NEXTVAL, newsId, newsText from news WHERE newsText is not null 
/

update notes set sourceTable='NEWS' where sourceTable is null
/

ALTER TABLE DOCUMENTS DROP  column DESCRIPTION
/

ALTER TABLE CATEGORIES DROP column DESCRIPTION
/

ALTER TABLE NEWS DROP column NEWSTEXT
/

ALTER TABLE DOCUMENTS ADD noteId INTEGER
/

ALTER TABLE CATEGORIES ADD noteId INTEGER
/

ALTER TABLE NEWS ADD noteId INTEGER
/

update DOCUMENTS set noteId=
(select noteId from notes where notes.sourceTable='DOCUMENTS' and notes.objectId=documents.documentId )
/

update CATEGORIES set noteId=
(select noteId from notes where notes.sourceTable='CATEGORIES' and notes.objectId=categories.categoryId )
/

update NEWS set noteId=
(select noteId from notes where notes.sourceTable='NEWS' and notes.objectId=news.newsId )
/

commit
/

