75 lines
2.9 KiB
Go
75 lines
2.9 KiB
Go
package migrations
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/pocketbase/dbx"
|
|
"github.com/pocketbase/pocketbase/daos"
|
|
m "github.com/pocketbase/pocketbase/migrations"
|
|
"github.com/pocketbase/pocketbase/models/schema"
|
|
"github.com/pocketbase/pocketbase/tools/types"
|
|
)
|
|
|
|
func init() {
|
|
m.Register(func(db dbx.Builder) error {
|
|
dao := daos.New(db);
|
|
|
|
collection, err := dao.FindCollectionByNameOrId("dd2l9a4vxpy2ni8")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
collection.ListRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public = true) || (author = @request.auth.id)")
|
|
|
|
collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public = true) || (author = @request.auth.id)")
|
|
|
|
collection.UpdateRule = types.Pointer("@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && (@collection.trails.author ?= @request.auth.id) || (author = @request.auth.id)")
|
|
|
|
collection.DeleteRule = types.Pointer("@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && (@collection.trails.author ?= @request.auth.id) || (author = @request.auth.id)")
|
|
|
|
// add
|
|
new_author := &schema.SchemaField{}
|
|
if err := json.Unmarshal([]byte(`{
|
|
"system": false,
|
|
"id": "r0mj3tkr",
|
|
"name": "author",
|
|
"type": "relation",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"collectionId": "_pb_users_auth_",
|
|
"cascadeDelete": false,
|
|
"minSelect": null,
|
|
"maxSelect": 1,
|
|
"displayFields": null
|
|
}
|
|
}`), new_author); err != nil {
|
|
return err
|
|
}
|
|
collection.Schema.AddField(new_author)
|
|
|
|
return dao.SaveCollection(collection)
|
|
}, func(db dbx.Builder) error {
|
|
dao := daos.New(db);
|
|
|
|
collection, err := dao.FindCollectionByNameOrId("dd2l9a4vxpy2ni8")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
collection.ListRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public = true)")
|
|
|
|
collection.ViewRule = types.Pointer("(@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && @collection.trails.author ?= @request.auth.id) || (@collection.trails.summit_logs.id ?= id && @collection.trails.public = true)")
|
|
|
|
collection.UpdateRule = types.Pointer("@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && (@collection.trails.author ?= @request.auth.id)")
|
|
|
|
collection.DeleteRule = types.Pointer("@request.auth.id != \"\" && @collection.trails.summit_logs.id ?= id && (@collection.trails.author ?= @request.auth.id)")
|
|
|
|
// remove
|
|
collection.Schema.RemoveField("r0mj3tkr")
|
|
|
|
return dao.SaveCollection(collection)
|
|
})
|
|
}
|