create table `ACADEMIC_PROGRAM` (
	`ID_INTERNAL` int(11) NOT NULL,
	`OID` bigint unsigned,
	`OID_SITE` bigint unsigned,
	`OID_SENDER` bigint unsigned,
	`PREVAILING_SCIENTIFIC_AREA` text,
	`CREATOR` text,
	`TIPO_CURSO` text,
	`NOME` text,
	`OJB_CONCRETE_CLASS` varchar(255) NOT NULL DEFAULT '',
	`MINISTRY_CODE` text,
	`ACRONYM` text,
	`ECTS_CREDITS` double,
	`GRADE_SCALE` text,
	`NAME_EN` text,
	`OID_ADMINISTRATIVE_OFFICE` bigint unsigned,
	`OID_PHD_PROGRAM_UNIT` bigint unsigned,
	`ID_CARD_NAME` text,
	`NAME` text,
	`OID_DEGREE` bigint unsigned,
	`OID_SERVICE_AGREEMENT_TEMPLATE` bigint unsigned,
	`OID_UNIT` bigint unsigned,
	`OID_PHD_PROGRAM` bigint unsigned,
	`SIGLA` text,
	`WHEN_CREATED` timestamp NULL default NULL,
	`OID_ROOT_DOMAIN_OBJECT` bigint unsigned,
	primary key (OID),
	index (OID),
	index (OID_ADMINISTRATIVE_OFFICE),
	index (OID_ROOT_DOMAIN_OBJECT)
) ENGINE=InnoDB, character set utf8;

insert into ACADEMIC_PROGRAM (
	ID_INTERNAL, OID, OID_SITE, OID_SENDER, PREVAILING_SCIENTIFIC_AREA, TIPO_CURSO, NOME,
	OJB_CONCRETE_CLASS, MINISTRY_CODE, ECTS_CREDITS, GRADE_SCALE, NAME_EN, ID_CARD_NAME,
	OID_UNIT, OID_PHD_PROGRAM, SIGLA, OID_ROOT_DOMAIN_OBJECT
)
select
	ID_INTERNAL, OID, OID_SITE, OID_SENDER, PREVAILING_SCIENTIFIC_AREA, TIPO_CURSO, NOME,
	OJB_CONCRETE_CLASS, MINISTRY_CODE, ECTS_CREDITS, GRADE_SCALE, NAME_EN, ID_CARD_NAME,
	OID_UNIT, OID_PHD_PROGRAM, SIGLA, OID_ROOT_DOMAIN_OBJECT
from DEGREE;

-- Generated with pt.utl.ist.scripts.runOnce.unit.MigratePhdPrograms

update PHD_PROGRAM set ID_INTERNAL = ID_INTERNAL + (select max(ID_INTERNAL) from DEGREE);
update PHD_PROGRAM as I, PHD_PROGRAM_PHD_PROGRAM_FOCUS_AREA as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, PROCESS as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, INSTITUTION_PHD_CANDIDACY_PERIOD_PHD_PROGRAMS as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, ALERT as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, ACADEMIC_PROGRAM as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, PHD_PROGRAM_CONTEXT_PERIOD as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, PARTY as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, SERVICE_AGREEMENT_TEMPLATE as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM as I, PHD_PROGRAM_INFORMATION as O set O.OID_PHD_PROGRAM = I.ID_INTERNAL + (1072 << 32) where I.OID = O.OID_PHD_PROGRAM;
update PHD_PROGRAM set OID = (1072 << 32) + ID_INTERNAL;

-- End of generated with pt.utl.ist.scripts.runOnce.unit.MigratePhdPrograms

insert into ACADEMIC_PROGRAM (
	ID_INTERNAL, OID, CREATOR, WHEN_CREATED, OID_DEGREE, OID_PHD_PROGRAM_UNIT,
	OID_ROOT_DOMAIN_OBJECT, NAME, ACRONYM, OID_SERVICE_AGREEMENT_TEMPLATE
)
select
	ID_INTERNAL, OID, CREATOR, WHEN_CREATED, OID_DEGREE, OID_PHD_PROGRAM_UNIT,
	OID_ROOT_DOMAIN_OBJECT, NAME, ACRONYM, OID_SERVICE_AGREEMENT_TEMPLATE
from PHD_PROGRAM;

update ACADEMIC_PROGRAM as AP, FF$DOMAIN_CLASS_INFO as DI set AP.OJB_CONCRETE_CLASS = DI.DOMAIN_CLASS_NAME where AP.OID >> 32 = DI.DOMAIN_CLASS_ID;

drop table DEGREE;
drop table PHD_PROGRAM;
