Files
sm-bm-plugin/updates/20261002234500_make_course_id_nullable.go
Jakub Zych 71b848a376 Adopt SummerCMS v0.1.1 admin features
Datepickers on native time.Time / lagoon.Date fields, file uploads on
materials, readings and class sessions managed from the course form
(course_id made nullable).
2026-10-03 06:03:34 +02:00

28 lines
1.1 KiB
Go

package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// MakeCourseIDNullable returns the 20261002234500_make_course_id_nullable
// gormigrate entry: class sessions and readings may have no course while
// the course form that creates them is not saved yet. The relation managers
// on the course form hold such rows in deferred_bindings, and the first save
// of the course sets course_id; deferred:purge deletes abandoned ones.
func MakeCourseIDNullable() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20261002234500_make_course_id_nullable",
Migrate: func(tx *gorm.DB) error {
return execAll(tx, `ALTER TABLE jz_bm_class_sessions ALTER COLUMN course_id DROP NOT NULL;
ALTER TABLE jz_bm_readings ALTER COLUMN course_id DROP NOT NULL`)
},
Rollback: func(tx *gorm.DB) error {
return execAll(tx, `DELETE FROM jz_bm_class_sessions WHERE course_id IS NULL;
DELETE FROM jz_bm_readings WHERE course_id IS NULL;
ALTER TABLE jz_bm_class_sessions ALTER COLUMN course_id SET NOT NULL;
ALTER TABLE jz_bm_readings ALTER COLUMN course_id SET NOT NULL`)
},
}
}