Files
htwkalender/services/data-manager/migrations/1687801090_initial_superuser.go
2025-04-22 09:43:19 +02:00

32 lines
814 B
Go

package migrations
import (
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
superusers, err := app.FindCollectionByNameOrId(core.CollectionNameSuperusers)
if err != nil {
return err
}
record := core.NewRecord(superusers)
// note: the values can be eventually loaded via os.Getenv(key)
// or from a special local config file
record.Set("email", "demo@htwkalender.de")
record.Set("password", "htwkalender-demo")
return app.Save(record)
}, func(app core.App) error { // optional revert operation
record, _ := app.FindAuthRecordByEmail(core.CollectionNameSuperusers, "demo@htwkalender.de")
if record == nil {
return nil // probably already deleted
}
return app.Delete(record)
})
}