Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/Database/Migrations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ applyMigrations currVersion migrations = do

-- | List of migrations
migrationList :: [MigrationWrapper]
migrationList = [MigrationWrapper {version=2, script=renamePostTables}]
migrationList = [
MigrationWrapper {version=2, script=renamePostTables},
MigrationWrapper {version=3, script=splitTimes}
]

-- | Migration script which renames the Post tables to Program
renamePostTables :: Migration
Expand All @@ -40,6 +43,13 @@ renamePostTables = do
addMigration True "ALTER TABLE post_category RENAME TO program_category;"
addMigration True "ALTER TABLE program_category RENAME COLUMN post TO program;"

-- | Migration script to add proper support for year-long courses
splitTimes :: Migration
splitTimes = do
addMigration True "ALTER TABLE times RENAME COLUMN first_room TO location;"
addMigration True "ALTER TABLE times DROP COLUMN second_room;"
addMigration True "ALTER TABLE times ADD session varchar(32);"

-- | Gets the current version of the database.
-- If no version is defined, initialize the
-- version to the latest version and return that.
Expand Down
13 changes: 6 additions & 7 deletions app/Database/Tables.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ Meeting
UniqueMeeting code session section

Times
session T.Text Maybe
weekDay Double
startHour Double
endHour Double
meeting MeetingId
firstRoom T.Text Maybe
secondRoom T.Text Maybe
location T.Text Maybe

Breadth
description T.Text
Expand Down Expand Up @@ -312,22 +312,21 @@ convertTimeVals _ _ _ = (5.0, 25.0, 25.0)
-- | Convert Times into Time
buildTime :: Times -> SqlPersistM Time
buildTime t = do
room1 <- getBuilding (timesFirstRoom t)
room2 <- getBuilding (timesSecondRoom t)
room1 <- getBuilding (timesLocation t)
return $ Time (timesWeekDay t)
(timesStartHour t)
(timesEndHour t)
room1
room2
Nothing -- Temporary null data

buildTimes :: Key Meeting -> Time' -> Times
buildTimes meetingKey t =
Times (weekDay' t)
Times (Just "") -- Temporary null data
(weekDay' t)
(startHour' t)
(endHour' t)
meetingKey
(firstLocation' t)
(secondLocation' t)

-- | Given a building code, get the persistent Building associated with it
getBuilding :: Maybe T.Text -> SqlPersistM (Maybe Building)
Expand Down