Skip to content

Add Quarter table to the database

Otto Visser requested to merge backend_quarter into master

In this commit, the following functionality is changed:

  • The database now includes a Quarter table. This table has booleans interest (for gathering interest) and availability (for gathering availability). The first boolean is moved from Schedule.
  • The code is edited to comply with the specified new database schema.

In order to update your database, I have supplied the following update script:

-- Create Quarter Database
CREATE TABLE Quarter (
    year int NOT NULL,
    quarter int NOT NULL,
    interest boolean NOT NULL DEFAULT false,
    availability boolean NOT NULL DEFAULT false,
    CONSTRAINT Quarter_pk PRIMARY KEY (year,quarter)
);

-- Duplicate current quarters in the database from both CourseEdition and Schedule
INSERT INTO Quarter (year, quarter) SELECT year, quarter FROM CourseEdition;
INSERT INTO Quarter (year, quarter, interest) SELECT year, quarter, interest FROM Schedule ON DUPLICATE KEY UPDATE Quarter.interest = Schedule.interest;

-- Only use the commented out commands if the altering tables does not work. In this case, please check whether the year and quarter columns of the erroring class are
-- equal to the Quarter columns by running:
-- SHOW CREATE TABLE ERRORTABLE;
-- SHOW CREATE TABLE Quarter;
-- and comparing the year and quarter column of the two.

-- Add Foreign key constraints
-- SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE CourseEdition ADD CONSTRAINT CourseEdition_Quarter FOREIGN KEY CourseEdition_Quarter (year,quarter) REFERENCES Quarter (year,quarter);
ALTER TABLE Note ADD CONSTRAINT Note_Quarter FOREIGN KEY Note_Quarter (year,quarter) REFERENCES Quarter (year,quarter);
ALTER TABLE Schedule ADD CONSTRAINT Schedule_Quarter FOREIGN KEY Schedule_Quarter (year,quarter) REFERENCES Quarter (year,quarter);
ALTER TABLE Timeslot ADD CONSTRAINT Timeslot_Quarter FOREIGN KEY Timeslot_Quarter (year,quarter) REFERENCES Quarter (year,quarter);
-- SET FOREIGN_KEY_CHECKS = 1

-- The commented command below is only to be used if the CourseEdition has a UNIQUE called course_code. You can check this by running SHOW CREATE TABLE CourseEdition
-- Miscellaneous updates
-- ALTER TABLE CourseEdition DROP INDEX course_code;
ALTER TABLE CourseEdition ADD UNIQUE INDEX CourseEdition_course_code (course_code,year,quarter);
-- The next line breaks backwards compatibility.
-- ALTER TABLE Schedule DROP COLUMN interest;

Please read through the comments in the script as they give additional information on running the script.

Edited by Otto Visser

Merge request reports

Loading