feat: revision-check material writes

- add jz_bm_materials.revision (default 1), read-only for GORM
- bump it only on content changes (models.ReviseMaterial)
- PUT /materials/{id} locks the row and answers 409 to a stale revision
- management answers carry revision and updated_at, the student detail
  carries revision
This commit is contained in:
Jakub Zych
2026-11-08 23:33:34 +01:00
parent 94ca257c6f
commit 237069c827
12 changed files with 611 additions and 17 deletions

View File

@@ -0,0 +1,23 @@
package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// AddRevisionToMaterials returns the
// 20261109120000_add_revision_to_jz_bm_materials gormigrate entry: a material
// carries a revision, a version token that goes up by one on every change to
// its content, so a writer holding an older revision can be refused instead
// of overwriting a newer note. Existing materials start at revision 1.
func AddRevisionToMaterials() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20261109120000_add_revision_to_jz_bm_materials",
Migrate: func(tx *gorm.DB) error {
return execAll(tx, `ALTER TABLE jz_bm_materials ADD COLUMN revision INTEGER NOT NULL DEFAULT 1`)
},
Rollback: func(tx *gorm.DB) error {
return execAll(tx, `ALTER TABLE jz_bm_materials DROP COLUMN IF EXISTS revision`)
},
}
}