DROP TABLE IF EXISTS `T_S_D_PROCESS`;
DROP TABLE IF EXISTS `TEACHER_SERVICE_DISTRIBUTION`;
CREATE TABLE `T_S_D_PROCESS` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`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` TEXT,
	`AUTOMATIC_VALUATION_GROUP` TEXT,
	`OMISSION_CONFIGURATION_GROUP` TEXT,
	`TSD_COURSES_AND_TEACHERS_MANAGEMENT_GROUP` TEXT,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;

DROP TABLE IF EXISTS `T_S_D_PROCESS_PHASE`;
DROP TABLE IF EXISTS `VALUATION_PHASE`;
CREATE TABLE `T_S_D_PROCESS_PHASE` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_T_S_D_PROCESS` int(11) NOT NULL default 0,
	`KEY_PREVIOUS_T_S_D_PROCESS_PHASE` int(11) default NULL,
	`KEY_NEXT_T_S_D_PROCESS_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 `T_S_D_TEACHER`;
DROP TABLE IF EXISTS `VALUATION_TEACHER`;
CREATE TABLE `T_S_D_TEACHER` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`OJB_CONCRETE_CLASS` varchar(250) NOT NULL default ' ',
	`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 `TEACHER_SERVICE_DISTRIBUTION`;
DROP TABLE IF EXISTS `VALUATION_GROUPING`;
CREATE TABLE `TEACHER_SERVICE_DISTRIBUTION` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_T_S_D_PROCESS_PHASE` int(11) NOT NULL default 0,
	`KEY_PARENT` int(11) default NULL,	
	`NAME` varchar(255) default NULL,
	`COURSES_AND_TEACHERS_VALUATION_MANAGERS` TEXT,
	`COURSES_AND_TEACHERS_MANAGEMENT_GROUP` TEXT,
	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,
	`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,
	`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 `T_S_D_COURSE`;
DROP TABLE IF EXISTS `COURSE_VALUATION`;
CREATE TABLE `T_S_D_COURSE` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`OJB_CONCRETE_CLASS` varchar(250) NOT NULL default ' ',
	`KEY_EXECUTION_PERIOD` int(11) NOT NULL default '0',
	`KEY_COMPETENCE_COURSE` int(11) default NULL,
	`KEY_CURRICULAR_COURSE` int(11) default NULL,
	`KEY_T_S_D_CURRICULAR_COURSE_GROUP` int(11) default NULL,
	`FIRST_TIME_ENROLLED_STUDENTS_MANUAL` int(11) default 0,
	`FIRST_TIME_ENROLLED_STUDENTS_TYPE` varchar(255) default NULL,
	`SECOND_TIME_ENROLLED_STUDENTS_MANUAL` int(11)  default 0,
	`SECOND_TIME_ENROLLED_STUDENTS_TYPE` varchar(255) default NULL,
	`IS_ACTIVE` tinyint(1) NOT NULL,
	`NAME` varchar(255) default NULL,
	PRIMARY KEY (`ID_INTERNAL`)
) Type=InnoDB;


DROP TABLE IF EXISTS `T_S_D_CURRICULAR_LOAD`;
CREATE TABLE `T_S_D_CURRICULAR_LOAD` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_T_S_D_COURSE` int(11) NOT NULL default 0,
	`TYPE` varchar(255) default NULL,
	`HOURS_PER_SHIFT_MANUAL` double default NULL,
	`TIME_TABLE_SLOTS` int(11) default NULL,
	`FREQUENCY` double NOT NULL default 1,
	`HOURS_MANUAL` double NOT NULL default 0,
	`HOURS_TYPE` varchar(255) default NULL,
	`STUDENTS_PER_SHIFT_MANUAL` double NOT NULL default 0,
	`STUDENTS_PER_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_FIRST_TIME_ENROLLED_STUDENTS_PER_SHIFT_TYPE` varchar(255) default NULL,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_SHIFT_MANUAL` double NOT NULL default 1,
	`WEIGHT_SECOND_TIME_ENROLLED_STUDENTS_PER_SHIFT_TYPE` varchar(255) default NULL,
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;


DROP TABLE IF EXISTS `T_S_D_PROFESSORSHIP`;
DROP TABLE IF EXISTS `PROFESSORSHIP_VALUATION`;
CREATE TABLE `T_S_D_PROFESSORSHIP` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_ROOT_DOMAIN_OBJECT` int(11) NOT NULL default '0',
	`KEY_T_S_D_COURSE` int(11) NOT NULL default 0,
	`KEY_T_S_D_TEACHER` int(11) NOT NULL default 0,
	`HOURS_MANUAL` double default 0,
	`HOURS_TYPE` varchar(255) default NULL,
	`TYPE` varchar(255) default NULL,
	PRIMARY KEY (`ID_INTERNAL`)
) Type = InnoDB;


DROP TABLE IF EXISTS `T_S_D_TEACHER_TEACHER_SERVICE_DISTRIBUTION`;
DROP TABLE IF EXISTS `VALUATION_TEACHER_VALUATION_GROUPING`;
CREATE TABLE `T_S_D_TEACHER_TEACHER_SERVICE_DISTRIBUTION` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_T_S_D_TEACHER` int(11) NOT NULL default 0,
	`KEY_TEACHER_SERVICE_DISTRIBUTION` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`),
	UNIQUE KEY `U1` (`KEY_T_S_D_TEACHER`,`KEY_TEACHER_SERVICE_DISTRIBUTION`),
  	KEY `KEY_T_S_D_TEACHER` (`KEY_T_S_D_TEACHER`),
	KEY `KEY_TEACHER_SERVICE_DISTRIBUTION` (`KEY_TEACHER_SERVICE_DISTRIBUTION`)
) Type = InnoDB;


DROP TABLE IF EXISTS `VALUATION_COMPETENCE_COURSE_TEACHER_SERVICE_DISTRIBUTION`;
DROP TABLE IF EXISTS `VALUATION_COMPETENCE_COURSE_VALUATION_GROUPING`;
DROP TABLE IF EXISTS `T_S_D_COURSE_TEACHER_SERVICE_DISTRIBUTION`;
CREATE TABLE `T_S_D_COURSE_TEACHER_SERVICE_DISTRIBUTION` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_T_S_D_COURSE` int(11) NOT NULL default 0,
	`KEY_TEACHER_SERVICE_DISTRIBUTION` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`),
	UNIQUE KEY `U1` (`KEY_T_S_D_COURSE`,`KEY_TEACHER_SERVICE_DISTRIBUTION`),
  	KEY `KEY_T_S_D_COURSE` (`KEY_T_S_D_COURSE`),
	KEY `KEY_TEACHER_SERVICE_DISTRIBUTION` (`KEY_TEACHER_SERVICE_DISTRIBUTION`)
) Type = InnoDB;


DROP TABLE IF EXISTS `T_S_D_PROCESS_EXECUTION_PERIOD`;
DROP TABLE IF EXISTS `TEACHER_SERVICE_DISTRIBUTION_EXECUTION_PERIOD`;
CREATE TABLE `T_S_D_PROCESS_EXECUTION_PERIOD` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_T_S_D_PROCESS` int(11) NOT NULL default 0,
	`KEY_EXECUTION_PERIOD` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`),
	UNIQUE KEY `U1` (`KEY_T_S_D_PROCESS`,`KEY_EXECUTION_PERIOD`),
  	KEY `KEY_T_S_D_PROCESS` (`KEY_T_S_D_PROCESS`),
	KEY `KEY_EXECUTION_PERIOD` (`KEY_EXECUTION_PERIOD`)
) Type = InnoDB;


DROP TABLE IF EXISTS `VALUATION_CURRICULAR_COURSE_CURRICULAR_YEAR`;
DROP TABLE IF EXISTS `T_S_D_VIRTUAL_COURSE_GROUP_CURRICULAR_YEAR`;

DROP TABLE IF EXISTS `T_S_D_VIRTUAL_COURSE_GROUP_DEGREE_CURRICULAR_PLAN`;
CREATE TABLE `T_S_D_VIRTUAL_COURSE_GROUP_DEGREE_CURRICULAR_PLAN` (
	`ID_INTERNAL` int(11) NOT NULL auto_increment,
	`KEY_T_S_D_VIRTUAL_COURSE_GROUP` int(11) NOT NULL default 0,
	`KEY_DEGREE_CURRICULAR_PLAN` int(11) NOT NULL default 0,
	PRIMARY KEY (`ID_INTERNAL`),
	UNIQUE KEY `U1` (`KEY_T_S_D_VIRTUAL_COURSE_GROUP`,`KEY_DEGREE_CURRICULAR_PLAN`),
  	KEY `KEY_T_S_D_VIRTUAL_COURSE_GROUP` (`KEY_T_S_D_VIRTUAL_COURSE_GROUP`),
	KEY `KEY_DEGREE_CURRICULAR_PLAN` (`KEY_DEGREE_CURRICULAR_PLAN`)
) Type = InnoDB;

ALTER TABLE COMPETENCE_COURSE DROP COLUMN KEY_VALUATION_COMPETENCE_COURSE;
ALTER TABLE DEGREE_MODULE DROP COLUMN KEY_VALUATION_CURRICULAR_COURSE;
