From 3afc79ceb68ad9c420844d53becae8e7332fdffc Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Thu, 4 May 2023 17:03:43 +0200 Subject: [PATCH] fix: fix autogenerated migration with surgical update and use collection name instead of id - Run go mod tidy --- server/go.mod | 6 ++- server/migrations/1683208972_updated_files.go | 50 ++++++++----------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/server/go.mod b/server/go.mod index 9f0ba9b..62f4cc1 100644 --- a/server/go.mod +++ b/server/go.mod @@ -2,7 +2,10 @@ module github.com/Dan6erbond/share-me go 1.19 -require github.com/pocketbase/pocketbase v0.15.2 +require ( + github.com/pocketbase/dbx v1.10.0 + github.com/pocketbase/pocketbase v0.15.2 +) require ( github.com/AlecAivazis/survey/v2 v2.3.6 // indirect @@ -48,7 +51,6 @@ require ( github.com/mattn/go-isatty v0.0.18 // indirect github.com/mattn/go-sqlite3 v1.14.16 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/pocketbase/dbx v1.10.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cobra v1.7.0 // indirect diff --git a/server/migrations/1683208972_updated_files.go b/server/migrations/1683208972_updated_files.go index 7b7024e..977f987 100644 --- a/server/migrations/1683208972_updated_files.go +++ b/server/migrations/1683208972_updated_files.go @@ -11,46 +11,36 @@ import ( func init() { m.Register(func(db dbx.Builder) error { - dao := daos.New(db); + dao := daos.New(db) - collection, err := dao.FindCollectionByNameOrId("vnfvpvktvaivqe2") + collection, err := dao.FindCollectionByNameOrId("files") if err != nil { return err } - // update - edit_file := &schema.SchemaField{} - json.Unmarshal([]byte(`{ - "system": false, - "id": "zybfkrpp", - "name": "file", - "type": "file", - "required": false, - "unique": false, - "options": { - "maxSelect": 1, - "maxSize": 10737418240, - "mimeTypes": [ - "image/jpeg", - "image/png", - "image/svg+xml", - "image/gif", - "image/webp", - "video/mp4" - ], - "thumbs": [ - "1200x630" - ], - "protected": false + for _, f := range collection.Schema.Fields() { + if f.Name == "file" { + f.Options = &schema.FileOptions{ + MaxSelect: 1, + MaxSize: 5242880, + MimeTypes: []string{ + "image/jpeg", + "image/png", + "image/svg+xml", + "image/gif", + "image/webp", + "video/mp4", + }, + Thumbs: []string{"1200x630"}, + } } - }`), edit_file) - collection.Schema.AddField(edit_file) + } return dao.SaveCollection(collection) }, func(db dbx.Builder) error { - dao := daos.New(db); + dao := daos.New(db) - collection, err := dao.FindCollectionByNameOrId("vnfvpvktvaivqe2") + collection, err := dao.FindCollectionByNameOrId("files") if err != nil { return err }