feat: add the study data models and schema migrations
Courses, meetings, class sessions, deadlines, readings with per-user progress, materials with tags and file attachments. Timestamps are stored in UTC and held as Europe/Warsaw text so the admin text inputs can write them.
This commit is contained in:
31
updates/20261002120154_create_jz_bm_meetings.go
Normal file
31
updates/20261002120154_create_jz_bm_meetings.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateMeetings returns the 20261002120154_create_jz_bm_meetings gormigrate entry:
|
||||
// the zjazdy.
|
||||
func CreateMeetings() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120154_create_jz_bm_meetings",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_meetings (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
number INTEGER NOT NULL UNIQUE CHECK (number > 0),
|
||||
starts_on DATE NOT NULL,
|
||||
ends_on DATE NOT NULL,
|
||||
notes TEXT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CHECK (ends_on >= starts_on)
|
||||
)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_meetings").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
38
updates/20261002120203_create_jz_bm_courses.go
Normal file
38
updates/20261002120203_create_jz_bm_courses.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateCourses returns the 20261002120203_create_jz_bm_courses gormigrate entry:
|
||||
// the przedmioty, one row per course and form.
|
||||
func CreateCourses() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120203_create_jz_bm_courses",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_courses (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
code VARCHAR(50) NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
form VARCHAR(20) NOT NULL CHECK (form IN ('wyklad', 'cwiczenia', 'konwersatorium', 'seminarium', 'inne')),
|
||||
lecturer VARCHAR(255) NULL,
|
||||
semester INTEGER NOT NULL CHECK (semester > 0),
|
||||
ects NUMERIC(4,1) NULL,
|
||||
assessment VARCHAR(100) NULL,
|
||||
description TEXT NULL,
|
||||
syllabus_url VARCHAR(2048) NULL,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (name, form, semester)
|
||||
);
|
||||
CREATE INDEX jz_bm_courses_semester_sort_index ON jz_bm_courses (semester, sort_order)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_courses").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
38
updates/20261002120204_create_jz_bm_class_sessions.go
Normal file
38
updates/20261002120204_create_jz_bm_class_sessions.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateClassSessions returns the 20261002120204_create_jz_bm_class_sessions gormigrate entry:
|
||||
// the zajęcia. Deleting a course deletes its sessions; deleting a meeting keeps them.
|
||||
func CreateClassSessions() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120204_create_jz_bm_class_sessions",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_class_sessions (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
course_id BIGINT NOT NULL REFERENCES jz_bm_courses (id) ON DELETE CASCADE,
|
||||
meeting_id BIGINT NULL REFERENCES jz_bm_meetings (id) ON DELETE SET NULL,
|
||||
starts_at TIMESTAMPTZ NOT NULL,
|
||||
ends_at TIMESTAMPTZ NOT NULL,
|
||||
room VARCHAR(100) NULL,
|
||||
kind VARCHAR(100) NULL,
|
||||
notes TEXT NULL,
|
||||
is_online BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CHECK (ends_at > starts_at),
|
||||
UNIQUE (course_id, starts_at)
|
||||
);
|
||||
CREATE INDEX jz_bm_class_sessions_starts_at_index ON jz_bm_class_sessions (starts_at);
|
||||
CREATE INDEX jz_bm_class_sessions_meeting_id_index ON jz_bm_class_sessions (meeting_id)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_class_sessions").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
33
updates/20261002120205_create_jz_bm_deadlines.go
Normal file
33
updates/20261002120205_create_jz_bm_deadlines.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateDeadlines returns the 20261002120205_create_jz_bm_deadlines gormigrate entry:
|
||||
// the terminarz. Deleting a course keeps its deadlines, unlinked.
|
||||
func CreateDeadlines() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120205_create_jz_bm_deadlines",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_deadlines (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
due_at TIMESTAMPTZ NOT NULL,
|
||||
course_id BIGINT NULL REFERENCES jz_bm_courses (id) ON DELETE SET NULL,
|
||||
kind VARCHAR(20) NOT NULL CHECK (kind IN ('zaliczenie', 'egzamin', 'praca', 'organizacyjne', 'inne')),
|
||||
description TEXT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
CREATE INDEX jz_bm_deadlines_due_at_index ON jz_bm_deadlines (due_at);
|
||||
CREATE INDEX jz_bm_deadlines_course_id_index ON jz_bm_deadlines (course_id)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_deadlines").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
34
updates/20261002120206_create_jz_bm_readings.go
Normal file
34
updates/20261002120206_create_jz_bm_readings.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateReadings returns the 20261002120206_create_jz_bm_readings gormigrate entry:
|
||||
// the lektury. Deleting a course deletes its readings.
|
||||
func CreateReadings() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120206_create_jz_bm_readings",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_readings (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
course_id BIGINT NOT NULL REFERENCES jz_bm_courses (id) ON DELETE CASCADE,
|
||||
title VARCHAR(500) NOT NULL,
|
||||
author VARCHAR(255) NULL,
|
||||
source VARCHAR(500) NULL,
|
||||
url VARCHAR(2048) NULL,
|
||||
is_required BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (course_id, title)
|
||||
)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_readings").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
29
updates/20261002120207_create_jz_bm_reading_progress.go
Normal file
29
updates/20261002120207_create_jz_bm_reading_progress.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateReadingProgress returns the 20261002120207_create_jz_bm_reading_progress gormigrate entry:
|
||||
// who has read which reading. The rows go with the reading or the golem15.user user.
|
||||
func CreateReadingProgress() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120207_create_jz_bm_reading_progress",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_reading_progress (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
reading_id BIGINT NOT NULL REFERENCES jz_bm_readings (id) ON DELETE CASCADE,
|
||||
user_id INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
read_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (reading_id, user_id)
|
||||
);
|
||||
CREATE INDEX jz_bm_reading_progress_user_id_index ON jz_bm_reading_progress (user_id)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_reading_progress").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
28
updates/20261002120208_create_jz_bm_tags.go
Normal file
28
updates/20261002120208_create_jz_bm_tags.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateTags returns the 20261002120208_create_jz_bm_tags gormigrate entry:
|
||||
// the material tags.
|
||||
func CreateTags() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120208_create_jz_bm_tags",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_tags (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
slug VARCHAR(100) NOT NULL UNIQUE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_tags").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
35
updates/20261002120209_create_jz_bm_materials.go
Normal file
35
updates/20261002120209_create_jz_bm_materials.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateMaterials returns the 20261002120209_create_jz_bm_materials gormigrate entry:
|
||||
// the study materials; a NULL published_at is a draft. Deleting a course keeps its materials, unlinked.
|
||||
func CreateMaterials() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120209_create_jz_bm_materials",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_materials (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
course_id BIGINT NULL REFERENCES jz_bm_courses (id) ON DELETE SET NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(20) NOT NULL CHECK (type IN ('pdf', 'notatka', 'link', 'inne')),
|
||||
body TEXT NULL,
|
||||
source VARCHAR(500) NULL,
|
||||
url VARCHAR(2048) NULL,
|
||||
published_at TIMESTAMPTZ NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
CREATE INDEX jz_bm_materials_published_at_index ON jz_bm_materials (published_at);
|
||||
CREATE INDEX jz_bm_materials_course_id_index ON jz_bm_materials (course_id)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_materials").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
27
updates/20261002120210_create_jz_bm_material_tag.go
Normal file
27
updates/20261002120210_create_jz_bm_material_tag.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateMaterialTag returns the 20261002120210_create_jz_bm_material_tag gormigrate entry:
|
||||
// the material-tag pivot.
|
||||
func CreateMaterialTag() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002120210_create_jz_bm_material_tag",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return execAll(tx, `CREATE TABLE jz_bm_material_tag (
|
||||
material_id BIGINT NOT NULL REFERENCES jz_bm_materials (id) ON DELETE CASCADE,
|
||||
tag_id BIGINT NOT NULL REFERENCES jz_bm_tags (id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (material_id, tag_id)
|
||||
);
|
||||
CREATE INDEX jz_bm_material_tag_tag_id_index ON jz_bm_material_tag (tag_id)`)
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("DROP TABLE IF EXISTS jz_bm_material_tag").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
22
updates/20261002121227_add_elective_group_to_courses.go
Normal file
22
updates/20261002121227_add_elective_group_to_courses.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Code generated by summer make. DO NOT EDIT.
|
||||
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AddElectiveGroupToCourses returns the 20261002121227_add_elective_group_to_courses gormigrate entry:
|
||||
// courses that share an elective_group are alternatives ("do wyboru").
|
||||
func AddElectiveGroupToCourses() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "20261002121227_add_elective_group_to_courses",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.Exec("ALTER TABLE jz_bm_courses ADD COLUMN elective_group VARCHAR(100) NULL").Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec("ALTER TABLE jz_bm_courses DROP COLUMN IF EXISTS elective_group").Error
|
||||
},
|
||||
}
|
||||
}
|
||||
21
updates/exec.go
Normal file
21
updates/exec.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// execAll runs each semicolon-separated statement of sql in order. The
|
||||
// statements hold no semicolons of their own.
|
||||
func execAll(tx *gorm.DB, sql string) error {
|
||||
for _, stmt := range strings.Split(sql, ";") {
|
||||
if strings.TrimSpace(stmt) == "" {
|
||||
continue
|
||||
}
|
||||
if err := tx.Exec(stmt).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user