make all books public by default (revert visibility gating)
All checks were successful
Release / Test backend (push) Successful in 5m47s
Release / Test UI (push) Successful in 1m4s
Release / Build and push images (push) Successful in 6m20s
Release / Deploy to prod (push) Successful in 3m53s
Release / Deploy to homelab (push) Successful in 8s
Release / Gitea Release (push) Successful in 25s

This commit is contained in:
root
2026-04-27 11:46:05 +05:00
parent 51adf0e7a5
commit 7351756056
2 changed files with 43 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
package migrations
import (
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
coll, err := app.FindCollectionByNameOrId("books")
if err != nil {
return err
}
if coll.Fields.GetByName("visibility") == nil {
coll.Fields.Add(&core.TextField{Name: "visibility"})
if err := app.Save(coll); err != nil {
return err
}
}
const perPage = 200
for page := 1; ; page++ {
records, err := app.FindRecordsByFilter(
"books", `visibility="admin_only"`, "+id", perPage, (page-1)*perPage, nil,
)
if err != nil || len(records) == 0 {
break
}
for _, rec := range records {
rec.Set("visibility", "public")
_ = app.Save(rec)
}
if len(records) < perPage {
break
}
}
return nil
}, func(app core.App) error {
return nil
})
}