21 Example Schema

This part uses a small university schema as its running example. The schema is deliberately light on constraints. Its purpose is to provide a familiar world for reading path expressions, not to model every rule of a university.

The main objects are students, courses, departments, enrolments, teaching sessions and assessments. An enrolment records that a student is taking a course. A department offers courses. A course may have prerequisites, scheduled sessions and assessments.


enum Day
{
    monday,
    tuesday,
    wednesday,
    thursday,
    friday
}

value TimeSlot
{
    Day day;
    Integer startMinute;
    Integer endMinute;
}

value Exam
{
    Day day;
    Integer durationMinutes;
    Integer weight;
    Integer maxMark;
}

value Assignment
{
    Day dueDay;
    Integer wordLimit;
    Integer weight;
    Integer maxMark;
}

value Project
{
    Day dueDay;
    Boolean groupWork;
    Integer estimatedHours;
    Integer weight;
    Integer maxMark;
}

variant Assessment
{
    Exam exam;
    Assignment assignment;
    Project project;
}

entity Department
{
    String name;

    Course course* where course.department = this;

    key { name };
}

entity Course
{
    String code;
    String title;
    Boolean advanced;
    Department department;

    Course prerequisite*;
    Session session* where session.course = this;
    Assessment assessment*;
    Enrolment enrolment* where enrolment.course = this;

    key { code };
}

entity Session
{
    Course course;
    TimeSlot time;
    String room;
}

entity Student
{
    String name;
    Course completed*;

    Enrolment enrolment* where enrolment.student = this;
    → Course enrolled* = enrolment.course;

    key { name };
}

entity Enrolment
{
    Student student;
    Course course;
    Boolean current;
    Integer mark?;
}

entity University
{
    Department department*;
    Course course*;
    Student student*;
    Enrolment enrolment*;
}

Some relationships are stored directly. For example, an Enrolment stores its student and course, and a Course stores its department. Other relationships are derived for convenient navigation. For example, Student.enrolled is calculated from the student's enrolments, and Department.course is the reverse direction of Course.department.

Assessment is a variant type: an assessment is an exam, an assignment or a project. Assessment attributes include numeric fields such as weight and maxMark so later chapters can use them for calculations and folds. Later examples also use Assessment to show that path expressions work over sum-shaped values as well as ordinary product-shaped values.

The following chapters use this schema to build up path expressions step by step: simple navigation first, then filters, naming, reshaping, summaries and the common places where the wrong mental model leads to mistakes.