Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7351756056 |
@@ -86,12 +86,11 @@ func (s *Store) WriteMetadata(ctx context.Context, meta domain.BookMeta) error {
|
||||
return fmt.Errorf("WriteMetadata: %w", err)
|
||||
}
|
||||
if err == ErrNotFound {
|
||||
// New scraped book — default to admin_only visibility.
|
||||
postPayload := make(map[string]any, len(patchPayload)+1)
|
||||
for k, v := range patchPayload {
|
||||
postPayload[k] = v
|
||||
}
|
||||
postPayload["visibility"] = domain.VisibilityAdminOnly
|
||||
postPayload["visibility"] = domain.VisibilityPublic
|
||||
postErr := s.pb.post(ctx, "/api/collections/books/records", postPayload, nil)
|
||||
if postErr == nil {
|
||||
return nil
|
||||
|
||||
42
backend/migrations/20260427000001_make_all_books_public.go
Normal file
42
backend/migrations/20260427000001_make_all_books_public.go
Normal 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
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user