DROP TABLE IF EXISTS `TEACHER_SERVICE_DISTRIBUTION`;
CREATE TABLE `TEACHER_SERVICE_DISTRIBUTION` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_DEPARTMENT` int(11) NOT NULL default 0,
	`KEY_CREATOR` int(11) NOT NULL default 0,
	`NAME` varchar(255) default NULL,
	`PHASES_MANAGEMENT_GROUP` blob default NULL,
	`AUTOMATIC_VALUATION_GROUP` blob default NULL,
	`OMISSION_CONFIGURATION_GROUP` blob default NULL,
	`VALUATION_COMPETENCE_COURSES_AND_TEACHERS_MANAGEMENT_GROUP` blob default NULL,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;


DROP TABLE IF EXISTS `VALUATION_PHASE`;
CREATE TABLE `VALUATION_PHASE` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_TEACHER_SERVICE_DISTRIBUTION` int(11) NOT NULL default 0,
	`KEY_PREVIOUS_VALUATION_PHASE` int(11) default NULL,
	`KEY_NEXT_VALUATION_PHASE` int(11) default NULL,
	`NAME` varchar(255) default NULL,
	`STATUS` varchar(255) NOT NULL default '',
	`STUDENTS_PER_THEORETICAL_SHIFT` int(11) default 0,
	`STUDENTS_PER_PRATICAL_SHIFT` int(11) default 0,
	`STUDENTS_PER_THEO_PRAT_SHIFT` int(11) default 0,
	`STUDENTS_PER_LABORATORIAL_SHIFT` int(11) default 0,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_THEO_SHIFT` double default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_PRAT_SHIFT` double default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_THEO_PRAT_SHIFT` double default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_LAB_SHIFT` double default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_THEO_SHIFT` double default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_PRAT_SHIFT` double default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_THEO_PRAT_SHIFT` double default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_LAB_SHIFT` double default 1,
	`IS_PUBLISHED` tinyint(1) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;

DROP TABLE IF EXISTS `VALUATION_TEACHER`;
CREATE TABLE `VALUATION_TEACHER` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',	
	`KEY_TEACHER` int(11) default NULL,
	`KEY_CATEGORY` int(11) default NULL,
	`NAME` varchar(255) default NULL,
	`REQUIRED_HOURS` int(11) default NULL,
	`EXTRA_CREDITS_NAME` varchar(255) NOT NULL default '',
	`EXTRA_CREDITS_VALUE` double default 0,
	`USING_EXTRA_CREDITS` tinyint(1) NOT NULL default 0,	
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;

DROP TABLE IF EXISTS `VALUATION_GROUPING`;
CREATE TABLE `VALUATION_GROUPING` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_VALUATION_PHASE` int(11) NOT NULL default 0,
	`KEY_PARENT` int(11) default NULL,	
	`NAME` varchar(255) default NULL,
	`COURSES_AND_TEACHERS_VALUATION_MANAGERS` blob default NULL,
	`COURSES_AND_TEACHERS_MANAGEMENT_GROUP` blob default NULL,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;

DROP TABLE IF EXISTS `VALUATION_COMPETENCE_COURSE`;
CREATE TABLE `VALUATION_COMPETENCE_COURSE` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_TEACHER_SERVICE_DISTRIBUTION` int(11) default NULL,	
	`KEY_COMPETENCE_COURSE` int(11) default NULL ,
	`NAME` varchar(255) default NULL,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;


DROP TABLE IF EXISTS `VALUATION_CURRICULAR_COURSE`;
CREATE TABLE `VALUATION_CURRICULAR_COURSE` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_VALUATION_COMPETENCE_COURSE` int(11) default NULL,
	`KEY_CURRICULAR_COURSE` int(11) default NULL,
	`KEY_DEGREE_CURRICULAR_PLAN` int(11) default NULL,
	`KEY_EXECUTION_PERIOD` int(11) default NULL,
	`ACRONYM` varchar(255) default NULL,
	`THEORETICAL_HOURS` double default 0,
	`PRATICAL_HOURS` double default 0,
	`THEO_PRAT_HOURS` double default 0,
	`LABORATORIAL_HOURS` double default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;

DROP TABLE IF EXISTS `COURSE_VALUATION`;
CREATE TABLE `COURSE_VALUATION` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`OJB_CONCRETE_CLASS` varchar(250) NOT NULL default ' ',
	`KEY_VALUATION_PHASE` int(11) default NULL,
	`KEY_EXECUTION_PERIOD` int(11) NOT NULL default '0',
	`KEY_VALUATION_COMPETENCE_COURSE` int(11) default NULL,
	`KEY_VALUATION_CURRICULAR_COURSE` int(11) default NULL,
	`KEY_CURRICULAR_COURSE_VALUATION_GROUP` int(11) default NULL,
	`FIRST_TIME_ENROLLED_STUDENTS_MANUAL` int(11) NOT NULL default 0,
	`FIRST_TIME_ENROLLED_STUDENTS_TYPE` varchar(255) default NULL,
	`SECOND_TIME_ENROLLED_STUDENTS_MANUAL` int(11) NOT NULL default 0,
	`SECOND_TIME_ENROLLED_STUDENTS_TYPE` varchar(255) default NULL,
	`STUDENTS_PER_THEORETICAL_SHIFT_MANUAL` int(11) NOT NULL default 0,
	`STUDENTS_PER_THEORETICAL_SHIFT_TYPE` varchar(255) default NULL,
	`STUDENTS_PER_PRATICAL_SHIFT_MANUAL` int(11) NOT NULL default 0,
	`STUDENTS_PER_PRATICAL_SHIFT_TYPE` varchar(255) default NULL,
	`STUDENTS_PER_THEO_PRAT_SHIFT_MANUAL` int(11) NOT NULL default 0,
	`STUDENTS_PER_THEO_PRAT_SHIFT_TYPE` varchar(255) default NULL,
	`STUDENTS_PER_LABORATORIAL_SHIFT_MANUAL` int(11) NOT NULL default 0,
	`STUDENTS_PER_LABORATORIAL_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_THEO_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_THEO_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_PRAT_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_PRAT_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_THEO_PRAT_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_THEO_PRAT_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_LAB_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_LAB_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_THEO_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_THEO_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_PRAT_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_PRAT_SHIFT_TYPE` varchar(255) default NULL,	
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_THEO_PRAT_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_THEO_PRAT_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_LAB_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_LAB_SHIFT_TYPE` varchar(255) default NULL,							
	`THEORETICAL_HOURS_MANUAL` int(11) NOT NULL default 0,
	`THEORETICAL_HOURS_TYPE` varchar(255) default NULL,
	`PRATICAL_HOURS_MANUAL` int(11) NOT NULL default 0,
	`PRATICAL_HOURS_TYPE` varchar(255) default NULL,	
	`THEO_PRAT_HOURS_MANUAL` int(11) NOT NULL default 0,
	`THEO_PRAT_HOURS_TYPE` varchar(255) default NULL,	
	`LABORATORIAL_HOURS_MANUAL` int(11) NOT NULL default 0,
	`LABORATORIAL_HOURS_TYPE` varchar(255) default NULL,		
	`IS_ACTIVE` tinyint(1) NOT NULL,
	`USING_CURRICULAR_COURSE_VALUATIONS` tinyint(1) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;

DROP TABLE IF EXISTS `PROFESSORSHIP_VALUATION`;
CREATE TABLE `PROFESSORSHIP_VALUATION` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_COURSE_VALUATION` int(11) NOT NULL default 0,
	`KEY_VALUATION_TEACHER` int(11) NOT NULL default 0,
	`THEORETICAL_HOURS_MANUAL` double default 0,
	`THEORETICAL_HOURS_TYPE` varchar(255) default NULL,
	`PRATICAL_HOURS_MANUAL` double default 0,
	`PRATICAL_HOURS_TYPE` varchar(255) default NULL,	
	`THEO_PRAT_HOURS_MANUAL` double default 0,
	`THEO_PRAT_HOURS_TYPE` varchar(255) default NULL,	
	`LABORATORIAL_HOURS_MANUAL` double default 0,
	`LABORATORIAL_HOURS_TYPE` varchar(255) default NULL,	
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;

DROP TABLE IF EXISTS `VALUATION_TEACHER_VALUATION_GROUPING`;
CREATE TABLE `VALUATION_TEACHER_VALUATION_GROUPING` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_VALUATION_TEACHER` int(11) NOT NULL default 0,
	`KEY_VALUATION_GROUPING` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;

DROP TABLE IF EXISTS `VALUATION_COMPETENCE_COURSE_VALUATION_GROUPING`;
CREATE TABLE `VALUATION_COMPETENCE_COURSE_VALUATION_GROUPING` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_VALUATION_COMPETENCE_COURSE` int(11) NOT NULL default 0,
	`KEY_VALUATION_GROUPING` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;

DROP TABLE IF EXISTS `TEACHER_SERVICE_DISTRIBUTION_EXECUTION_PERIOD`;
CREATE TABLE `TEACHER_SERVICE_DISTRIBUTION_EXECUTION_PERIOD` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_TEACHER_SERVICE_DISTRIBUTION` int(11) NOT NULL default 0,
	`KEY_EXECUTION_PERIOD` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;

DROP TABLE IF EXISTS `VALUATION_CURRICULAR_COURSE_CURRICULAR_YEAR`;
CREATE TABLE `VALUATION_CURRICULAR_COURSE_CURRICULAR_YEAR` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`ACK_OPT_LOCK` int(11) default NULL,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_VALUATION_CURRICULAR_COURSE` int(11) NOT NULL default 0,
	`KEY_CURRICULAR_YEAR` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;

ALTER TABLE COMPETENCE_COURSE DROP COLUMN KEY_VALUATION_COMPETENCE_COURSE;
ALTER TABLE DEGREE_MODULE DROP COLUMN KEY_VALUATION_CURRICULAR_COURSE;
ALTER TABLE COMPETENCE_COURSE ADD COLUMN KEY_VALUATION_COMPETENCE_COURSE int(11) default null;
ALTER TABLE DEGREE_MODULE ADD COLUMN KEY_VALUATION_CURRICULAR_COURSE int(11) default null;
