create table EQUIVALENCE_PLAN_ENTRY_NEW_DEGREE_MODULE (KEY_DEGREE_MODULE int(11) not null, KEY_EQUIVALENCE_PLAN_ENTRY int(11) not null,  primary key (KEY_DEGREE_MODULE, KEY_EQUIVALENCE_PLAN_ENTRY), key(KEY_DEGREE_MODULE), key(KEY_EQUIVALENCE_PLAN_ENTRY)) type=InnoDB;
create table EQUIVALENCE_PLAN_ENTRY_OLD_DEGREE_MODULE (KEY_DEGREE_MODULE int(11) not null, KEY_EQUIVALENCE_PLAN_ENTRY int(11) not null,  primary key (KEY_DEGREE_MODULE, KEY_EQUIVALENCE_PLAN_ENTRY), key(KEY_DEGREE_MODULE), key(KEY_EQUIVALENCE_PLAN_ENTRY)) type=InnoDB;
alter table DEGREE_CURRICULAR_PLAN add index (KEY_EQUIVALENCE_PLAN);
alter table EQUIVALENCE_PLAN_ENTRY change column KEY_PREVIOUS_COURSE_GROUP_FOR_NEW_CURRICULAR_COURSES KEY_PREVIOUS_COURSE_GROUP_FOR_NEW_DEGREE_MODULES int(11) default null;
alter table EQUIVALENCE_PLAN add index (KEY_SOURCE_DEGREE_CURRICULAR_PLAN);
alter table STUDENT_CURRICULAR_PLAN add index (KEY_EQUIVALENCE_PLAN);

insert into EQUIVALENCE_PLAN_ENTRY_NEW_DEGREE_MODULE (KEY_DEGREE_MODULE, KEY_EQUIVALENCE_PLAN_ENTRY)
    select KEY_DEGREE_MODULE, KEY_CURRICULAR_COURSE_EQUIVALENCE_PLAN_ENTRY
    from CURRICULAR_COURSE_EQUIVALENCE_PLAN_ENTRY_NEW_DEGREE_MODULE;

insert into EQUIVALENCE_PLAN_ENTRY_OLD_DEGREE_MODULE (KEY_DEGREE_MODULE, KEY_EQUIVALENCE_PLAN_ENTRY)
    select KEY_CURRICULAR_COURSE, KEY_CURRICULAR_COURSE_EQUIVALENCE_PLAN_ENTRY
    from CURRICULAR_COURSE_EQUIVALENCE_PLAN_ENTRY_OLD_CURRICULAR_COURSE;

insert into EQUIVALENCE_PLAN_ENTRY_NEW_DEGREE_MODULE (KEY_DEGREE_MODULE, KEY_EQUIVALENCE_PLAN_ENTRY)
    select KEY_NEW_COURSE_GROUP, ID_INTERNAL
    from EQUIVALENCE_PLAN_ENTRY
    where EQUIVALENCE_PLAN_ENTRY.OJB_CONCRETE_CLASS = 'net.sourceforge.fenixedu.domain.CourseGroupEquivalencePlanEntry';

insert into EQUIVALENCE_PLAN_ENTRY_OLD_DEGREE_MODULE (KEY_DEGREE_MODULE, KEY_EQUIVALENCE_PLAN_ENTRY)
    select KEY_OLD_COURSE_GROUP, ID_INTERNAL
    from EQUIVALENCE_PLAN_ENTRY
    where EQUIVALENCE_PLAN_ENTRY.OJB_CONCRETE_CLASS = 'net.sourceforge.fenixedu.domain.CourseGroupEquivalencePlanEntry';

alter table EQUIVALENCE_PLAN_ENTRY drop column OJB_CONCRETE_CLASS, drop column KEY_NEW_COURSE_GROUP, drop column KEY_OLD_COURSE_GROUP;
