feat: per-student owned flag on readings

- new table jz_bm_reading_ownership and its migration
  20261026120000_create_jz_bm_reading_ownership
- PUT and DELETE /_bm/api/v1/readings/{id}/owned, idempotent
- owned_at on every reading in /readings and /courses/{id}
- read semantics, progress routes and counts unchanged
This commit is contained in:
2026-10-26 11:11:22 +01:00
parent 85cae45cb9
commit cf84f1d0e8
12 changed files with 142 additions and 14 deletions

View File

@@ -0,0 +1,29 @@
package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// CreateReadingOwnership returns the
// 20261026120000_create_jz_bm_reading_ownership gormigrate entry: who owns a
// copy of which reading, apart from who has read it. The rows go with the
// reading or the golem15.user user.
func CreateReadingOwnership() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "20261026120000_create_jz_bm_reading_ownership",
Migrate: func(tx *gorm.DB) error {
return execAll(tx, `CREATE TABLE jz_bm_reading_ownership (
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,
owned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (reading_id, user_id)
);
CREATE INDEX jz_bm_reading_ownership_user_id_index ON jz_bm_reading_ownership (user_id)`)
},
Rollback: func(tx *gorm.DB) error {
return tx.Exec("DROP TABLE IF EXISTS jz_bm_reading_ownership").Error
},
}
}