Merge remote-tracking branch 'origin/master'

# Conflicts:
#	plugin.go
This commit is contained in:
2026-10-19 22:35:54 +02:00
4 changed files with 126 additions and 46 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"embed"
"fmt"
"io/fs"
"log/slog"
"net/http"
@@ -18,6 +19,7 @@ import (
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/bouncer"
"git.golem15.com/golem15/summercms/modules/lagoon"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/party"
"git.golem15.com/golem15/summercms/modules/surf"
@@ -204,7 +206,25 @@ func (p *Plugin) MailLayouts() map[string]string {
}
func (p *Plugin) Commands() []bonfire.Command {
return append([]bonfire.Command{console.RequirePasswordChange(p.app), console.BackfillHandles(p.app)}, console.APITokenCommands(p.app)...)
return append([]bonfire.Command{console.RequirePasswordChange(p.withDB), console.BackfillHandles(p.app)}, console.APITokenCommands(p.app, p.withDB)...)
}
// withDB runs fn with the application's database: the one the serve command
// published, or, when a console command runs, one opened from the config for
// the duration of fn.
func (p *Plugin) withDB(ctx context.Context, fn func(*gorm.DB) error) error {
if p == nil || p.app == nil {
return fmt.Errorf("golem15.user: app is nil")
}
if gdb, ok := p.app.Lookup[*gorm.DB](); ok && gdb != nil {
return fn(gdb)
}
sqlDB, gdb, err := lagoon.OpenFromApp(ctx, p.app)
if err != nil {
return err
}
defer sqlDB.Close()
return fn(gdb)
}
func (p *Plugin) Migrations() []*gormigrate.Migration { return updates.All() }