• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Courseography / courseography / d64d18ba-ec0c-490a-ad8b-28e03fcc853b

13 Nov 2025 03:55PM UTC coverage: 55.03% (-0.1%) from 55.155%
d64d18ba-ec0c-490a-ad8b-28e03fcc853b

Pull #1607

circleci

web-flow
Merge branch 'master' into rename-post-table-to-program
Pull Request #1607: Rename post table to program

490 of 960 branches covered (51.04%)

Branch coverage included in aggregate %.

21 of 52 new or added lines in 6 files covered. (40.38%)

28 existing lines in 2 files now uncovered.

2223 of 3970 relevant lines covered (55.99%)

158.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.81
/app/Database/Database.hs
1
{-|
2
    Module      : Database.Database
3
    Description : Main module for database course seeding.
4

5
The main module for parsing course information from the web and
6
inserting it into the database. Run when @cabal run database@ is executed.
7
-}
8

9
module Database.Database
10
    (populateCalendar, setupDatabase) where
11

12
import Config (databasePath, runDb)
13
import Control.Monad (void)
14
import Control.Monad.IO.Class (liftIO)
15
import Data.Maybe (fromMaybe)
16
import Data.Text as T (findIndex, length, reverse, take, unpack)
17
import Database.CourseVideoSeed (seedVideos)
18
import Database.Migrations (getDatabaseVersion)
19
import Database.Persist.Sqlite (insert_, runMigration, runMigrationQuiet)
20
import Database.Tables
21
import System.Directory (createDirectoryIfMissing)
22
import WebParsing.ArtSciParser (parseCalendar)
23

24

25
distTableSetUpStr :: String
26
distTableSetUpStr = "Distribution table set up"
×
27
breathTableSetUpStr :: String
28
breathTableSetUpStr = "breadth table set up"
×
29

30

31
-- | Creates the database if it doesn't exist and runs migrations.
32
setupDatabase :: Bool -> IO ()
33
setupDatabase quiet = do
1✔
34
    -- Create db folder if it doesn't exist
35
    dbPath <- liftIO databasePath
5✔
36
    let ind = (T.length dbPath -) . fromMaybe 0 . T.findIndex (=='/') . T.reverse $ dbPath
5✔
37
        db = T.unpack $ T.take ind dbPath
5✔
38
    createDirectoryIfMissing True db
5✔
39

40
    -- Match SQL database with ORM, then initialize schema version table
41
    let migrateFunction = if quiet then void . runMigrationQuiet else runMigration
5!
42
    runDb $ void $ migrateFunction migrateAll >> getDatabaseVersion
5✔
43

44
-- | Sets up the course information from Artsci Calendar
45
populateCalendar :: IO ()
UNCOV
46
populateCalendar = do
×
UNCOV
47
    populateStaticInfo
×
UNCOV
48
    parseCalendar
×
49

50
-- | Sets up the tables and seeds the videos for the database.
51
populateStaticInfo :: IO ()
UNCOV
52
populateStaticInfo = do
×
UNCOV
53
    setupDistributionTable
×
UNCOV
54
    print distTableSetUpStr
×
55
    setupBreadthTable
×
56
    print breathTableSetUpStr
×
57
    seedVideos
×
58

59
-- | Sets up the Distribution table.
60
setupDistributionTable :: IO ()
UNCOV
61
setupDistributionTable = runDb $ do
×
UNCOV
62
    insert_ $ Distribution "Humanities"
×
UNCOV
63
    insert_ $ Distribution "Social Science"
×
64
    insert_ $ Distribution "Science"
×
65

66
-- | Sets up the Breadth table.
67
setupBreadthTable :: IO ()
UNCOV
68
setupBreadthTable = runDb $ do
×
UNCOV
69
    insert_ $ Breadth "Creative and Cultural Representations (1)"
×
UNCOV
70
    insert_ $ Breadth "Thought, Belief, and Behaviour (2)"
×
71
    insert_ $ Breadth "Society and its Institutions (3)"
×
72
    insert_ $ Breadth "Living Things and Their Environment (4)"
×
73
    insert_ $ Breadth "The Physical and Mathematical Universes (5)"
×
74
    insert_ $ Breadth "No Breadth"
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc