first commit
This commit is contained in:
39
apps/server/migrations/1734898795_init_superuser.go
Normal file
39
apps/server/migrations/1734898795_init_superuser.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
// add up queries...
|
||||
|
||||
// get environment variable
|
||||
email := os.Getenv("SUPERUSER_EMAIL")
|
||||
password := os.Getenv("SUPERUSER_PASSWORD")
|
||||
if email == "" || password == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
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", email)
|
||||
record.Set("password", password)
|
||||
|
||||
return app.Save(record)
|
||||
}, func(app core.App) error {
|
||||
// add down queries...
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user