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).
This commit is contained in:
27
updates/20261002234500_make_course_id_nullable.go
Normal file
27
updates/20261002234500_make_course_id_nullable.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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`)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user