-- Merge the HOMEPAGE table in the SITE table

ALTER TABLE `SITE`
	ADD COLUMN `KEY_PERSON` INTEGER,
	ADD COLUMN `ACTIVATED` BOOLEAN,
	ADD COLUMN `SHOW_UNIT` BOOLEAN,
	ADD COLUMN `SHOW_PHOTO` BOOLEAN,
	ADD COLUMN `SHOW_EMAIL` BOOLEAN,
	ADD COLUMN `SHOW_CATEGORY` BOOLEAN,
	ADD COLUMN `SHOW_ALTERNATIVE_HOMEPAGE` BOOLEAN,
	ADD COLUMN `SHOW_TELEPHONE` BOOLEAN,
	ADD COLUMN `SHOW_WORK_TELEPHONE` BOOLEAN,
	ADD COLUMN `SHOW_MOBILE_TELEPHONE` BOOLEAN,
	ADD COLUMN `SHOW_ACTIVE_STUDENT_CURRICULAR_PLANS` BOOLEAN,
	ADD COLUMN `SHOW_ALUMNI_DEGREES` BOOLEAN,
	ADD COLUMN `SHOW_CURRENT_EXECUTION_COURSES` BOOLEAN,
	ADD COLUMN `SHOW_CURRENT_ATTENDING_EXECUTION_COURSES` BOOLEAN,
	ADD COLUMN `SHOW_RESEARCH_UNIT_HOMEPAGE` BOOLEAN,
	ADD COLUMN `RESEARCH_UNIT` LONGTEXT,
	ADD COLUMN `RESEARCH_UNIT_HOMEPAGE` VARCHAR(250);

INSERT INTO `SITE` 
	(`OJB_CONCRETE_CLASS`, `KEY_ROOT_DOMAIN_OBJECT`, `KEY_PERSON`, `ACTIVATED`, 
	 `SHOW_UNIT`, `SHOW_PHOTO`, `SHOW_EMAIL`, `SHOW_CATEGORY`, `SHOW_ALTERNATIVE_HOMEPAGE`, 
	 `SHOW_TELEPHONE`, `SHOW_WORK_TELEPHONE`, `SHOW_MOBILE_TELEPHONE`, 
	 `SHOW_ACTIVE_STUDENT_CURRICULAR_PLANS`, `SHOW_ALUMNI_DEGREES`, 
	 `SHOW_CURRENT_EXECUTION_COURSES`, `SHOW_CURRENT_ATTENDING_EXECUTION_COURSES`, 
	 `SHOW_RESEARCH_UNIT_HOMEPAGE`, `RESEARCH_UNIT`, `RESEARCH_UNIT_HOMEPAGE`)
	SELECT 'net.sourceforge.fenixedu.domain.homepage.Homepage', 1, H.`KEY_PERSON`, H.`ACTIVATED`, 
	 	H.`SHOW_UNIT`, H.`SHOW_PHOTO`, H.`SHOW_EMAIL`, H.`SHOW_CATEGORY`, H.`SHOW_ALTERNATIVE_HOMEPAGE`, 
	 	H.`SHOW_TELEPHONE`, H.`SHOW_WORK_TELEPHONE`, H.`SHOW_MOBILE_TELEPHONE`, 
	 	H.`SHOW_ACTIVE_STUDENT_CURRICULAR_PLANS`, H.`SHOW_ALUMNI_DEGREES`, 
	 	H.`SHOW_CURRENT_EXECUTION_COURSES`, H.`SHOW_CURRENT_ATTENDING_EXECUTION_COURSES`, 
	 	H.`SHOW_RESEARCH_UNIT_HOMEPAGE`, H.`RESEARCH_UNIT`, H.`RESEARCH_UNIT_HOMEPAGE` 
	 FROM HOMEPAGE AS H;
	 
UPDATE `PARTY` AS P, `SITE` AS S
	SET P.`KEY_HOMEPAGE` = S.`ID_INTERNAL`
	WHERE P.`ID_INTERNAL` = S.`KEY_PERSON`;

DROP TABLE `HOMEPAGE`;

-- Remove cache of sequence number
DELETE FROM OJB_HL_SEQ WHERE TABLENAME = 'SEQ_SITE';