adds comments

This commit is contained in:
Christian Beutel
2024-04-03 22:28:34 +02:00
parent 8af1efaf20
commit 76522c808a
23 changed files with 714 additions and 46 deletions

View File

@@ -0,0 +1,92 @@
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": "lf06qip3f4d11yk",
"created": "2024-04-03 18:44:47.201Z",
"updated": "2024-04-03 18:44:47.201Z",
"name": "comments",
"type": "base",
"system": false,
"schema": [
{
"system": false,
"id": "0udwb0kl",
"name": "text",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"pattern": ""
}
},
{
"system": false,
"id": "fhgxdiam",
"name": "rating",
"type": "number",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"noDecimal": false
}
},
{
"system": false,
"id": "7lwo1mxx",
"name": "author",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "_pb_users_auth_",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}
],
"indexes": [],
"listRule": "",
"viewRule": "",
"createRule": "",
"updateRule": "",
"deleteRule": "",
"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("lf06qip3f4d11yk")
if err != nil {
return err
}
return dao.DeleteCollection(collection)
})
}

View File

@@ -0,0 +1,55 @@
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"
)
func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// add
new_comments := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "phhhroww",
"name": "comments",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "lf06qip3f4d11yk",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": null,
"displayFields": null
}
}`), new_comments)
collection.Schema.AddField(new_comments)
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// remove
collection.Schema.RemoveField("phhhroww")
return dao.SaveCollection(collection)
})
}

View File

@@ -0,0 +1,55 @@
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"
)
func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("lf06qip3f4d11yk")
if err != nil {
return err
}
// add
new_trail := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "snrlpxar",
"name": "trail",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "e864strfxo14pm4",
"cascadeDelete": true,
"minSelect": null,
"maxSelect": 1,
"displayFields": null
}
}`), new_trail)
collection.Schema.AddField(new_trail)
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("lf06qip3f4d11yk")
if err != nil {
return err
}
// remove
collection.Schema.RemoveField("snrlpxar")
return dao.SaveCollection(collection)
})
}

View File

@@ -0,0 +1,55 @@
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"
)
func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// remove
collection.Schema.RemoveField("phhhroww")
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// add
del_comments := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "phhhroww",
"name": "comments",
"type": "relation",
"required": false,
"presentable": false,
"unique": false,
"options": {
"collectionId": "lf06qip3f4d11yk",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": null,
"displayFields": null
}
}`), del_comments)
collection.Schema.AddField(del_comments)
return dao.SaveCollection(collection)
})
}