2026-10-08 15:38:12 -06:00
|
|
|
package commands
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-10-14 15:36:58 -06:00
|
|
|
"code.destrealm.net/zancarius/justusbot/internal/app"
|
2026-10-08 15:38:12 -06:00
|
|
|
"code.destrealm.net/zancarius/justusbot/internal/models"
|
|
|
|
|
"code.destrealm.net/zancarius/justusbot/internal/settings"
|
|
|
|
|
"github.com/urfave/cli/v3"
|
2026-10-14 15:36:58 -06:00
|
|
|
"go.destrealm.net/embedder"
|
2026-10-08 15:38:12 -06:00
|
|
|
"go.destrealm.net/errors"
|
|
|
|
|
"go.destrealm.net/logging/v3"
|
|
|
|
|
"go.destrealm.net/vfs"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type installer struct {
|
|
|
|
|
fs vfs.VFS
|
|
|
|
|
logger *logging.Log
|
|
|
|
|
settings *settings.Settings
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initInstaller(fs vfs.VFS, settings *settings.Settings) (*installer, error) {
|
|
|
|
|
return &installer{
|
|
|
|
|
fs,
|
|
|
|
|
logging.Get("initializer"),
|
|
|
|
|
settings,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (inst *installer) DoInstall(ctx context.Context, cmd *cli.Command) error {
|
2026-10-14 15:36:58 -06:00
|
|
|
// Embedder needs examining. It seems that it doesn't support correctly
|
|
|
|
|
// listing directories, possibly due to changes since Golang 1.16.
|
|
|
|
|
//
|
|
|
|
|
// This code is being added here to support embedded migrations in the
|
|
|
|
|
// future.
|
|
|
|
|
efs := embedder.NewEmbedderVFS(app.LoadBucket("migrations"))
|
|
|
|
|
|
|
|
|
|
lfs := vfs.NewLayeredFS()
|
|
|
|
|
lfs.AddFS(efs)
|
|
|
|
|
lfs.AddFS(inst.fs)
|
|
|
|
|
|
2026-10-20 15:15:50 -06:00
|
|
|
db := models.OpenDatabase(ctx, inst.settings)
|
2026-10-14 15:36:58 -06:00
|
|
|
fmt.Println("migrated database:", inst.settings.System.DSN)
|
|
|
|
|
err := db.Migrate(lfs)
|
2026-10-08 15:38:12 -06:00
|
|
|
if err != nil {
|
|
|
|
|
inst.logger.Error(errors.Unfurl(err))
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|