Skip to content

Commit

Permalink
fix: 🐛 Add migration for default services, canCreateAccounts now defa…
Browse files Browse the repository at this point in the history
…ults to true
  • Loading branch information
CRBroughton committed Nov 15, 2023
1 parent 0bdfe91 commit ad34d82
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-beans-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"forager": patch
---

Add migration for default services, canCreateAccounts now defaults to true
50 changes: 50 additions & 0 deletions db/migrations/1700070534_default_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package migrations

import (
"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 {
dao := daos.New(db)

collection, err := dao.FindCollectionByNameOrId("Services")
if err != nil {
return err
}

record := models.NewRecord(collection)

record.Set("id", 1)
record.Set("canCreateAccounts", true)

err = dao.SaveRecord(record)
if err != nil {
return err
}

return nil
}, func(db dbx.Builder) error {
dao := daos.New(db)

collection, err := dao.FindCollectionByNameOrId("Services")
if err != nil {
return err
}

record, err := dao.FindRecordById(collection.Id, "1")
if err != nil {
return err
}

err = dao.DeleteRecord(record)
if err != nil {
return err
}

return nil
})
}

0 comments on commit ad34d82

Please sign in to comment.