start migration to pocketbase 0.23

This commit is contained in:
Christian Beutel
2025-03-16 21:20:05 +01:00
parent 92433ec618
commit c765e6391d
14 changed files with 390 additions and 376 deletions

View File

@@ -1,20 +1,17 @@
package migrations
import (
"encoding/json"
"os"
"github.com/meilisearch/meilisearch-go"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models"
)
func init() {
client := meilisearch.New(os.Getenv("MEILI_URL"), meilisearch.WithAPIKey(os.Getenv("MEILI_MASTER_KEY")))
m.Register(func(db dbx.Builder) error {
m.Register(func(app core.App) error {
_, err := client.CreateIndex(&meilisearch.IndexConfig{
Uid: "trails",
PrimaryKey: "id",
@@ -665,13 +662,6 @@ func init() {
}
]`
collections := []*models.Collection{}
if err := json.Unmarshal([]byte(jsonData), &collections); err != nil {
return err
}
return daos.New(db).ImportCollections(collections, true, nil)
}, func(db dbx.Builder) error {
return nil
})
return app.ImportCollectionsByMarshaledJSON([]byte(jsonData), true)
}, nil)
}

View File

@@ -3,26 +3,22 @@ package migrations
import (
"encoding/json"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
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")
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// remove
collection.Schema.RemoveField("mcqce8l9")
collection.Fields.RemoveById("mcqce8l9")
// add
new_thumbnail := &schema.SchemaField{}
new_thumbnail := &core.NumberField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "k2giqyjq",
@@ -37,19 +33,17 @@ func init() {
"noDecimal": false
}
}`), new_thumbnail)
collection.Schema.AddField(new_thumbnail)
collection.Fields.Add(new_thumbnail)
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4")
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// add
del_thumbnail := &schema.SchemaField{}
del_thumbnail := &core.TextField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "mcqce8l9",
@@ -64,11 +58,11 @@ func init() {
"pattern": ""
}
}`), del_thumbnail)
collection.Schema.AddField(del_thumbnail)
collection.Fields.Add(del_thumbnail)
// remove
collection.Schema.RemoveField("k2giqyjq")
collection.Fields.RemoveById("k2giqyjq")
return dao.SaveCollection(collection)
return app.Save(collection)
})
}

View File

@@ -3,23 +3,19 @@ package migrations
import (
"encoding/json"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
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")
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// add
new_difficulty := &schema.SchemaField{}
new_difficulty := &core.SelectField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "dywtnynw",
@@ -37,20 +33,19 @@ func init() {
]
}
}`), new_difficulty)
collection.Schema.AddField(new_difficulty)
collection.Fields.Add(new_difficulty)
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
return app.Save(collection)
}, func(app core.App) error {
collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4")
collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4")
if err != nil {
return err
}
// remove
collection.Schema.RemoveField("dywtnynw")
collection.Fields.RemoveById("dywtnynw")
return dao.SaveCollection(collection)
return app.Save(collection)
})
}

View File

@@ -3,23 +3,20 @@ package migrations
import (
"encoding/json"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
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);
m.Register(func(app core.App) error {
collection, err := dao.FindCollectionByNameOrId("goeo2ubp103rzp9")
collection, err := app.FindCollectionByNameOrId("goeo2ubp103rzp9")
if err != nil {
return err
}
// add
new_photo := &schema.SchemaField{}
new_photo := &core.FileField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "tfhs3juh",
@@ -42,20 +39,19 @@ func init() {
"protected": false
}
}`), new_photo)
collection.Schema.AddField(new_photo)
collection.Fields.Add(new_photo)
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
return app.Save(collection)
}, func(app core.App) error {
collection, err := dao.FindCollectionByNameOrId("goeo2ubp103rzp9")
collection, err := app.FindCollectionByNameOrId("goeo2ubp103rzp9")
if err != nil {
return err
}
// remove
collection.Schema.RemoveField("tfhs3juh")
collection.Fields.RemoveById("tfhs3juh")
return dao.SaveCollection(collection)
return app.Save(collection)
})
}