refactor(10.2-01): nest framework packages under modules

- Move remaining beach packages and embedded admin assets\n- Rewrite framework, example, build, and gate paths
This commit is contained in:
Jakub Zych
2026-09-28 02:21:02 +02:00
parent ac1f6d14f4
commit 5e50b166ef
277 changed files with 303 additions and 303 deletions

View File

@@ -0,0 +1,88 @@
package lagoon
import (
"context"
"fmt"
"strings"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/modules/party"
"gorm.io/gorm"
)
// RuntimeCommands returns migrate, migrate:rollback, migrate:status, and key:generate.
// Serve is registered separately via surf.ServeCommand.
func RuntimeCommands(app *backpack.App, plugins []party.Plugin) []bonfire.Command {
return []bonfire.Command{
{
Name: "migrate",
Description: "Run plugin migrations in dependency order",
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
return withDB(ctx, app, func(gdb *gorm.DB) error {
if err := Migrate(gdb, plugins); err != nil {
return err
}
out.Success("migrations applied")
return nil
})
},
},
{
Name: "migrate:rollback",
Description: "Roll back the last migration of a plugin",
Flags: []bonfire.Flag{{
Name: "plugin",
Description: "Plugin ID whose last migration to roll back",
}},
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
plugin, _ := in.Flag("plugin")
return withDB(ctx, app, func(gdb *gorm.DB) error {
if err := RollbackLast(gdb, plugins, plugin); err != nil {
return err
}
if plugin == "" {
plugin = lastMigrationPlugin(plugins)
}
out.Success(fmt.Sprintf("rolled back last migration of %s", plugin))
return nil
})
},
},
{
Name: "migrate:status",
Description: "Show per-plugin migration history",
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
return withDB(ctx, app, func(gdb *gorm.DB) error {
rows, err := Status(gdb, plugins)
if err != nil {
return err
}
tableRows := make([][]string, 0, len(rows))
for _, row := range rows {
ids := "(none)"
if len(row.IDs) > 0 {
ids = strings.Join(row.IDs, ", ")
}
tableRows = append(tableRows, []string{row.Plugin, row.Table, ids})
}
out.Table([]string{"plugin", "table", "applied"}, tableRows)
return nil
})
},
},
KeyGenerateCommand(),
}
}
func withDB(ctx context.Context, app *backpack.App, fn func(*gorm.DB) error) error {
sqlDB, gdb, err := OpenFromApp(ctx, app)
if err != nil {
return err
}
defer sqlDB.Close()
if err := Publish(app, sqlDB, gdb); err != nil {
return err
}
return fn(gdb)
}