示例#1
0
package generate

import (
	"github.com/pkg/errors"

	"github.com/markbates/going/defaults"
	"github.com/markbates/pop"
	"github.com/spf13/cobra"
)

var FizzCmd = &cobra.Command{
	Use:     "fizz [name]",
	Aliases: []string{"migration"},
	Short:   "Generates Up/Down migrations for your database using fizz.",
	RunE: func(cmd *cobra.Command, args []string) error {
		if len(args) == 0 {
			return errors.New("You must supply a name for your migration!")
		}
		cflag := cmd.Flag("path")
		migrationPath := defaults.String(cflag.Value.String(), "./migrations")
		return pop.MigrationCreate(migrationPath, args[0], "fizz", nil, nil)
	},
}
示例#2
0
import (
	"fmt"

	"github.com/pkg/errors"

	"github.com/markbates/pop"
	"github.com/spf13/cobra"
)

var migrationType string

var depWarning = "[DEPRACTION WARNING] This command is deprecated. Please use `soda generate fizz` or `soda generate sql` instead."

var migrateCreateCmd = &cobra.Command{
	Use:   "create [name]",
	Short: depWarning,
	RunE: func(cmd *cobra.Command, args []string) error {
		fmt.Println(depWarning)
		if len(args) == 0 {
			return errors.New("You must supply a name for your migration!")
		}

		return pop.MigrationCreate(migrationPath, args[0], migrationType, nil, nil)
	},
}

func init() {
	migrateCmd.AddCommand(migrateCreateCmd)
	migrateCreateCmd.Flags().StringVarP(&migrationType, "type", "t", "fizz", "Which type of migration file do you want? fizz or sql?")
}
示例#3
0
文件: model.go 项目: markbates/pop
			return errors.Wrapf(err, "couldn't write to file %s", tfname)
		}
		fmt.Printf("> %s\n", tfname)

		md, _ := filepath.Abs(fname)
		goi := exec.Command("gofmt", "-w", md)
		out, err := goi.CombinedOutput()
		if err != nil {
			fmt.Printf("Received an error when trying to run gofmt -> %#v\n", err)
			fmt.Println(out)
		}

		if !skipMigration {
			cflag := cmd.Flag("path")
			migrationPath := defaults.String(cflag.Value.String(), "./migrations")
			err = pop.MigrationCreate(migrationPath, fmt.Sprintf("create_%s", model.Names.Table), "fizz", []byte(model.Fizz()), []byte(fmt.Sprintf("drop_table(\"%s\")", model.Names.Table)))
			if err != nil {
				return err
			}
		}

		return nil
	},
}

func colType(s string) string {
	switch s {
	case "text":
		return "string"
	case "time", "timestamp":
		return "time.Time"