commands

package
v0.0.0-...-09cfab7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MigrateCmd = &cobra.Command{
	Use:   "migrate [action] [optional arguments]",
	Short: "Run database migrations (e.g., create, up, down, force)",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		action := args[0]

		switch action {
		case "create":
			if len(args) < 2 {
				return errors.New("please provide a name for the migration")
			}
			migrationName := args[1]
			return createMigration(migrationName)

		case "up":
			return runMigration("up")

		case "down":
			return runMigration("down")

		case "force":
			if len(args) < 2 {
				return errors.New("please provide a version number to force")
			}
			version, err := strconv.Atoi(args[1])
			if err != nil {
				return fmt.Errorf("invalid version number: %v", err)
			}
			return forceMigration(version)

		default:
			return fmt.Errorf("unknown action: %s. Available actions: create, up, down, force", action)
		}
	},
}
View Source
var SeederCmd = &cobra.Command{
	Use:   "seed [seeder_name]",
	Short: "Run a specific database seeder",
	Long:  "Run a specific database seeder by name",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		seederName := args[0]

		seederFunc, found := seederRegistry[seederName]
		if !found {
			log.Errorf("Seeder '%s' not found. Available seeders: %v", seederName, availableSeeders())
			return fmt.Errorf("seeder '%s' not found; available seeders: %v", seederName, availableSeeders())
		}

		log.Infof("Running seeder: %s", seederName)
		seederFunc()
		return nil
	},
}

Functions

func InitCommands

func InitCommands(rootCmd *cobra.Command)

InitCommands adds all core commands to the root command

func RegisterSeeder

func RegisterSeeder(name string, seederFunc func())

RegisterSeeder allows external projects to add seeders to the registry

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL