121 lines
2.4 KiB
Go
121 lines
2.4 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"
|
|
)
|
|
|
|
func init() {
|
|
m.Register(func(db dbx.Builder) error {
|
|
jsonData := `{
|
|
"id": "khrcci2uqknny8h",
|
|
"created": "2024-12-20 17:33:49.887Z",
|
|
"updated": "2024-12-20 17:33:49.887Z",
|
|
"name": "notifications",
|
|
"type": "base",
|
|
"system": false,
|
|
"schema": [
|
|
{
|
|
"system": false,
|
|
"id": "b57prsbu",
|
|
"name": "type",
|
|
"type": "select",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"maxSelect": 1,
|
|
"values": [
|
|
"trail_create",
|
|
"list_create",
|
|
"new_follower",
|
|
"trail_comment"
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "1i2ycgle",
|
|
"name": "metadata",
|
|
"type": "json",
|
|
"required": false,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"maxSize": 2000000
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "pyimxu85",
|
|
"name": "seen",
|
|
"type": "bool",
|
|
"required": false,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "tmghd4vo",
|
|
"name": "recipient",
|
|
"type": "relation",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"collectionId": "_pb_users_auth_",
|
|
"cascadeDelete": false,
|
|
"minSelect": null,
|
|
"maxSelect": 1,
|
|
"displayFields": null
|
|
}
|
|
},
|
|
{
|
|
"system": false,
|
|
"id": "exqo1whj",
|
|
"name": "author",
|
|
"type": "relation",
|
|
"required": true,
|
|
"presentable": false,
|
|
"unique": false,
|
|
"options": {
|
|
"collectionId": "_pb_users_auth_",
|
|
"cascadeDelete": false,
|
|
"minSelect": null,
|
|
"maxSelect": 1,
|
|
"displayFields": null
|
|
}
|
|
}
|
|
],
|
|
"indexes": [],
|
|
"listRule": null,
|
|
"viewRule": null,
|
|
"createRule": null,
|
|
"updateRule": null,
|
|
"deleteRule": null,
|
|
"options": {}
|
|
}`
|
|
|
|
collection := &models.Collection{}
|
|
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
|
|
return err
|
|
}
|
|
|
|
return daos.New(db).SaveCollection(collection)
|
|
}, func(db dbx.Builder) error {
|
|
dao := daos.New(db);
|
|
|
|
collection, err := dao.FindCollectionByNameOrId("khrcci2uqknny8h")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return dao.DeleteCollection(collection)
|
|
})
|
|
}
|