Skip to content

Commit 71b2805

Browse files
committed
Removing old schema file in favor or per-table schema files.
Updating where necessary.
1 parent 98e4c9a commit 71b2805

File tree

12 files changed

+215
-170
lines changed

12 files changed

+215
-170
lines changed

schema/schema.sql

Lines changed: 0 additions & 164 deletions
This file was deleted.

schema/tables/buildings.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
DROP TABLE IF EXISTS buildings;
1010
CREATE TABLE buildings (
11-
`number` VARCHAR(3) PRIMARY KEY,
12-
`code` VARCHAR(3) UNIQUE,
11+
`number` VARCHAR(5) PRIMARY KEY,
12+
`code` VARCHAR(5) UNIQUE,
1313
`name` VARCHAR(100),
1414
`off_campus` BOOLEAN DEFAULT TRUE
1515
) Engine=InnoDb;

schema/tables/courses.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- -------------------------------------------------------------------------
2+
-- Courses table
3+
--
4+
-- @author Benjamin Russell ([email protected])
5+
-- @descrip Table for courses. These are linked to departments and quarters
6+
-- in a one quarter/department to many courses. These are also linked
7+
-- to sections in a one course to many sections fashion.
8+
-- -------------------------------------------------------------------------
9+
10+
-- TABLE CREATION ----------------------------------------------------------
11+
CREATE TABLE courses (
12+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
13+
`quarter` SMALLINT UNSIGNED NOT NULL,
14+
`department` INT UNSIGNED NOT NULL,
15+
`course` VARCHAR(4) NOT NULL,
16+
`credits` TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
17+
`title` VARCHAR(50) NOT NULL,
18+
`description` TEXT NOT NULL
19+
)ENGINE=InnoDb;
20+
21+
-- INDEXING ----------------------------------------------------------------
22+
ALTER TABLE `courses`
23+
ADD CONSTRAINT UQ_courses_quarter_department_course
24+
UNIQUE (`quarter`, `department`, `course`);
25+
26+
-- FOREIGN KEYS ------------------------------------------------------------
27+
ALTER TABLE `courses`
28+
ADD FOREIGN KEY FK_courses_quarter(`quarter`)
29+
REFERENCES `quarters`(`quarter`)
30+
ON DELETE CASCADE
31+
ON UPDATE CASCADE;
32+
33+
ALTER TABLE `courses`
34+
ADD FOREIGN KEY FK_courses_dept(`department`)
35+
REFERENCES `departments`(`id`)
36+
ON DELETE CASCADE
37+
ON UPDATE CASCADE;

schema/tables/departments.sql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ DROP TABLE IF EXISTS departments;
1111
CREATE TABLE departments (
1212
`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
1313
`school` INT UNSIGNED NOT NULL,
14-
`number` SMALLINT(4) UNSIGNED NULL DEFAULT NULL,
14+
`number` SMALLINT(4) UNSIGNED ZEROFILL NULL DEFAULT NULL,
1515
`code` VARCHAR(4) NULL DEFAULT NULL,
1616
`title` VARCHAR(100) NOT NULL,
1717
`qtrnums` VARCHAR(20) NULL DEFAULT NULL -- Group of corresponding department numbers from quarters
1818
) Engine=InnoDb;
1919

20+
-- UNIQUE CONSTRAINTS ------------------------------------------------------
21+
ALTER TABLE `departments`
22+
ADD CONSTRAINT UQ_departments_number
23+
UNIQUE (`number`);
24+
25+
ALTER TABLE `departments`
26+
ADD CONSTRAINT UQ_departments_code
27+
UNIQUE (`code`);
28+
2029
-- FOREIGN KEYS
2130
ALTER TABLE departments ADD INDEX departments(school);
2231
ALTER TABLE departments ADD CONSTRAINT fk_school FOREIGN KEY departments(school)

schema/tables/quarters.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- -------------------------------------------------------------------------
2+
-- Quarters Table
3+
--
4+
-- @author Benjamin Russell ([email protected])
5+
-- @descrip Table for quarters. Although RIT changed their formatting for quarters
6+
-- we convert their new format (2135) to the old format (20135) to
7+
-- preserve sorting.
8+
-- -------------------------------------------------------------------------
9+
10+
-- CREATE TABLE ------------------------------------------------------------
11+
CREATE TABLE quarters (
12+
`quarter` SMALLINT(5) UNSIGNED NOT NULL PRIMARY KEY,
13+
`start` DATE NOT NULL,
14+
`end` DATE NOT NULL,
15+
`breakstart` DATE NOT NULL,
16+
`breakend` DATE NOT NULL
17+
) ENGINE=InnoDb;

schema/tables/schedulecourses.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- -------------------------------------------------------------------------
2+
-- Saved Schedule Sections
3+
--
4+
-- @author Benjamin Russell ([email protected])
5+
-- @descrip Table for linking sections with saved schedules.
6+
-- -------------------------------------------------------------------------
7+
8+
-- CREATE TABLE ------------------------------------------------------------
9+
CREATE TABLE schedulecourses (
10+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
11+
`schedule` INT UNSIGNED NOT NULL,
12+
`section` INT UNSIGNED NOT NULL
13+
)ENGINE=InnoDb;
14+
15+
-- FOREIGN KEY CONSTRAINTS -------------------------------------------------
16+
ALTER TABLE `schedulecourses`
17+
ADD FOREIGN KEY FK_schedcourses_schedule(`schedule`)
18+
REFERENCES `schedules`(`id`)
19+
ON DELETE CASCADE
20+
ON UPDATE CASCADE;
21+
22+
ALTER TABLE `schedulecourses`
23+
ADD FOREIGN KEY FK_schedcourses_section(`section`)
24+
REFERENCES `sections`(`id`)
25+
ON DELETE CASCADE
26+
ON UPDATE CASCADE;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- -------------------------------------------------------------------------
2+
-- Saved Schedule Non-Course Items
3+
--
4+
-- @author Benjamin Russell ([email protected])
5+
-- @descrip Table for storing non-course items for saved schedules and linking
6+
-- them to saved schedules.
7+
-- -------------------------------------------------------------------------
8+
9+
CREATE TABLE schedulenoncourses (
10+
`id` INT UNSIGNED NOT NULL PRIMARY KEY,
11+
`schedule` INT UNSIGNED NOT NULL,
12+
`title` VARCHAR(30) NOT NULL,
13+
`day` TINYINT(1) UNSIGNED NOT NULL,
14+
`start` SMALLINT(4) UNSIGNED NOT NULL,
15+
`end` SMALLINT(4) UNSIGNED NOT NULL
16+
)ENGINE=InnoDb;
17+
18+
-- FOREIGN KEY REFERENCES --------------------------------------------------
19+
ALTER TABLE `schedulenoncourses`
20+
ADD FOREIGN KEY FK_schednoncourses_schedule(`schedule`)
21+
REFERENCES `schedules`(`id`)
22+
ON DELETE CASCADE
23+
ON UPDATE CASCADE;

schema/tables/schedules.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
-- @descrip A table for storing saved schedule records.
66
-- -------------------------------------------------------------------------
77

8-
CREATE TABLE schedule (
8+
CREATE TABLE schedules (
99
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, -- Will be displayed to user as hex
1010
-- @TODO Safely remove this column when old schedules have been pruned
1111
`oldid` VARCHAR(7) NULL DEFAULT NULL COLLATE latin1_general_cs, -- Old index from Resig's schedule maker. It's case sensitive
@@ -21,4 +21,11 @@ CREATE TABLE schedule (
2121
)ENGINE=InnoDb;
2222

2323
-- Add index to searchable columns
24-
ALTER TABLE schedule ADD INDEX (`oldid`);
24+
ALTER TABLE schedules ADD INDEX (`oldid`);
25+
26+
-- FOREIGN KEYS ------------------------------------------------------------
27+
ALTER TABLE `schedules`
28+
ADD FOREIGN KEY FK_schedules_quarter(`quarter`)
29+
REFERENCES `quarters`(`quarter`)
30+
ON UPDATE CASCADE
31+
ON DELETE SET NULL;

schema/tables/schools.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
-- TABLE CREATION ----------------------------------------------------------
1010
CREATE TABLE IF NOT EXISTS `schools` (
11-
`id` INT unsigned NOT NULL PRIMARY KEY,
11+
`id` INT UNSIGNED NOT NULL PRIMARY KEY,
1212
`number` tinyint(2) UNSIGNED ZEROFILL NULL DEFAULT NULL,
1313
`code` VARCHAR(5) NULL DEFAULT NULL,
1414
`title` varchar(30) NOT NULL,
1515
PRIMARY KEY (`id`)
1616
) ENGINE=InnoDb;
1717

1818
-- ADD INDEXES -------------------------------------------------------------
19+
ALTER TABLE `schools`
20+
ADD CONSTRAINT UQ_schools_number_code
21+
UNIQUE (`number`, `code`);

schema/tables/scrapelog.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- -------------------------------------------------------------------------
2+
-- Scrape Log Table
3+
--
4+
-- @author Benjamin Russell ([email protected])
5+
-- @descrip Rudimentary table for storing the status of past dump processing
6+
-- cron jobs.
7+
-- -------------------------------------------------------------------------
8+
9+
-- CREATE TABLE ------------------------------------------------------------
10+
CREATE TABLE scrapelog (
11+
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
12+
`timeStarted` INT(11) NOT NULL,
13+
`timeEnded` INT(11) NOT NULL,
14+
`quartersAdded` TINYINT(3) UNSIGNED NOT NULL,
15+
`coursesAdded` INT UNSIGNED NOT NULL,
16+
`coursesUpdated` INT UNSIGNED NOT NULL,
17+
`sectionsAdded` INT UNSIGNED NOT NULL,
18+
`sectionsUpdated` INT UNSIGNED NOT NULL,
19+
`failures` INT UNSIGNED NOT NULL
20+
)ENGINE=InnoDB;

0 commit comments

Comments
 (0)