alter table ROOT_DOMAIN_OBJECT ADD COLUMN KEY_RESIDENCE_MANAGEMENT_UNIT INTEGER;
alter table PARTY ADD COLUMN KEY_ROOT_DOMAIN_OBJECT_FOR_RESIDENCE_UNIT INTEGER;

alter table PARTY ADD INDEX(KEY_ROOT_DOMAIN_OBJECT_FOR_RESIDENCE_UNIT);
alter table ROOT_DOMAIN_OBJECT ADD INDEX(KEY_RESIDENCE_MANAGEMENT_UNIT);

update ROOT_DOMAIN_OBJECT SET KEY_RESIDENCE_MANAGEMENT_UNIT = (SELECT ID_INTERNAL FROM PARTY WHERE OJB_CONCRETE_CLASS='net.sourceforge.fenixedu.domain.organizationalStructure.ResidenceManagementUnit');

update PARTY SET KEY_ROOT_DOMAIN_OBJECT_FOR_RESIDENCE_UNIT='1' WHERE  OJB_CONCRETE_CLASS='net.sourceforge.fenixedu.domain.organizationalStructure.ResidenceManagementUnit';
