CREATE TABLE `group_name_criterias_equivalence` (
    `serial_gce` INT(11) NOT NULL AUTO_INCREMENT,
    `serial_aca` INT(11) NOT NULL,
    `name_gce` VARCHAR(45) NOT NULL,
    `status_gce` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    PRIMARY KEY (`serial_gce`),
    INDEX `fk_ group_name_criterias_equivalence_aca_idx` (`serial_aca` ASC),
    CONSTRAINT `fk_group_name_criterias_equivalence_aca` FOREIGN KEY (`serial_aca`)
        REFERENCES `academic_area` (`serial_aca`)
        ON DELETE NO ACTION ON UPDATE NO ACTION
);

  
CREATE TABLE `criterias_equivalence_setup` (
    `serial_ces` INT(11) NOT NULL AUTO_INCREMENT,
    `serial_scy` INT(11) NOT NULL,
    `serial_gce` INT(11) NOT NULL,
    `grade_max_criteria_ces` DECIMAL(5 , 2 ) NOT NULL,
    `grade_max_school_ces` DECIMAL(5 , 2 ) NOT NULL,
    `status_ces` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    PRIMARY KEY (`serial_ces`),
    INDEX `fk_criterias_eq_setup_scy_idx` (`serial_scy` ASC),
    INDEX `fk_criterias_eq_setup_gce_idx` (`serial_gce` ASC),
    CONSTRAINT `fk_criterias_eq_setup_scy` FOREIGN KEY (`serial_scy`)
        REFERENCES `school_year` (`serial_scy`)
        ON DELETE NO ACTION ON UPDATE NO ACTION,
    CONSTRAINT `fk_criterias_eq_setup_gce` FOREIGN KEY (`serial_gce`)
        REFERENCES `group_name_criterias_equivalence` (`serial_gce`)
        ON DELETE NO ACTION ON UPDATE NO ACTION
);    
    
    
    ALTER TABLE `subject_year_activity_criteria_period` 
ADD COLUMN `serial_gce` INT(11) NULL DEFAULT NULL AFTER `criteria_max_grade`;


ALTER TABLE `opt_subject_year_activity_criteria_period` 
ADD COLUMN `serial_gce` INT(11) NULL DEFAULT NULL AFTER `criteria_max_grade`;

ALTER TABLE `student_criteria_grade` 
ADD COLUMN `grade_criteria_scg` DECIMAL(8,5) NULL DEFAULT NULL AFTER `grade_scg`;

ALTER TABLE `opt_student_criteria_grade` 
ADD COLUMN `grade_criteria_osg` DECIMAL(8,5) NULL DEFAULT NULL AFTER `grade_osg`;

ALTER TABLE `activity` 
ADD COLUMN `has_grades_act` TINYINT(1) NOT NULL DEFAULT '1' AFTER `due_date_act`;

ALTER TABLE `opt_activity` 
ADD COLUMN `has_grades_opa` TINYINT(1) NOT NULL DEFAULT '1' AFTER `due_date_opa`;
