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:
29
updates/20261026120000_create_jz_bm_reading_ownership.go
Normal file
29
updates/20261026120000_create_jz_bm_reading_ownership.go
Normal 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
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user