| 1234567891011121314151617181920212223242526272829303132333435363738 |
- // Author: simon (ynwdlxm@163.com)
- // Date: 2025/7/16 11:24
- // Desc: seed 命令
- package cmd
- import (
- "github.com/spf13/cobra"
- "github.com/runningwater/gohub/database/seeders"
- "github.com/runningwater/gohub/pkg/console"
- "github.com/runningwater/gohub/pkg/seed"
- )
- var CmdDBSeed = &cobra.Command{
- Use: "seed",
- Short: "Insert fake data to the database",
- Run: runSeeders,
- Args: cobra.MaximumNArgs(1), // 只允许一个参数
- }
- func runSeeders(cmd *cobra.Command, args []string) {
- seeders.Initialize()
- if len(args) > 0 {
- name := args[0]
- seeder := seed.GetSeeder(name)
- if len(seeder.Name) > 0 {
- seed.RunSeeder(name)
- } else {
- console.Error("Seeder not found: " + name)
- }
- } else {
- // 默认运行全部迁移
- seed.RunAll()
- console.Success("Done seeding.")
- }
- }
|