justusbot/internal/commands/install.go
Benjamin A. Shelton 0f3bf8b87d
Added migrate up which is just a passthrough for what the installer
does (for now).

Eventually, this will be turned into a proper migration channel.
2026-10-22 21:23:35 -06:00

54 lines
1.3 KiB
Go

package commands
import (
"context"
"fmt"
"code.destrealm.net/zancarius/justusbot/internal/app"
"code.destrealm.net/zancarius/justusbot/internal/models"
"code.destrealm.net/zancarius/justusbot/internal/settings"
"github.com/urfave/cli/v3"
"go.destrealm.net/embedder"
"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 {
// 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)
db := models.OpenDatabase(ctx, inst.settings)
fmt.Println("migrated database:", inst.settings.System.DSN)
err := db.Migrate(lfs)
if err != nil {
inst.logger.Error(errors.Unfurl(err))
}
return nil
}
func (inst *installer) DoUp(ctx context.Context, cmd *cli.Command) error {
return inst.DoInstall(ctx, cmd)
}