1package admin23import (4 "fmt"56 "github.com/charmbracelet/soft-serve/cmd"7 "github.com/charmbracelet/soft-serve/pkg/backend"8 "github.com/charmbracelet/soft-serve/pkg/config"9 "github.com/charmbracelet/soft-serve/pkg/db"10 "github.com/charmbracelet/soft-serve/pkg/db/migrate"11 "github.com/spf13/cobra"12)1314var (15 // Command is the admin command.16 Command = &cobra.Command{17 Use: "admin",18 Short: "Administrate the server",19 }2021 migrateCmd = &cobra.Command{22 Use: "migrate",23 Short: "Migrate the database to the latest version",24 PersistentPreRunE: cmd.InitBackendContext,25 PersistentPostRunE: cmd.CloseDBContext,26 RunE: func(cmd *cobra.Command, _ []string) error {27 ctx := cmd.Context()28 db := db.FromContext(ctx)29 if err := migrate.Migrate(ctx, db); err != nil {30 return fmt.Errorf("migration: %w", err)31 }3233 return nil34 },35 }3637 rollbackCmd = &cobra.Command{38 Use: "rollback",39 Short: "Rollback the database to the previous version",40 PersistentPreRunE: cmd.InitBackendContext,41 PersistentPostRunE: cmd.CloseDBContext,42 RunE: func(cmd *cobra.Command, _ []string) error {43 ctx := cmd.Context()44 db := db.FromContext(ctx)45 if err := migrate.Rollback(ctx, db); err != nil {46 return fmt.Errorf("rollback: %w", err)47 }4849 return nil50 },51 }5253 syncHooksCmd = &cobra.Command{54 Use: "sync-hooks",55 Short: "Update repository hooks",56 PersistentPreRunE: cmd.InitBackendContext,57 PersistentPostRunE: cmd.CloseDBContext,58 RunE: func(c *cobra.Command, _ []string) error {59 ctx := c.Context()60 cfg := config.FromContext(ctx)61 be := backend.FromContext(ctx)62 if err := cmd.InitializeHooks(ctx, cfg, be); err != nil {63 return fmt.Errorf("initialize hooks: %w", err)64 }6566 return nil67 },68 }69)7071func init() {72 Command.AddCommand(73 syncHooksCmd,74 migrateCmd,75 rollbackCmd,76 )77}