Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ApplyCmd = &cobra.Command{ Use: "apply", Short: "apply migrations", Run: func(_ *cobra.Command, _ []string) { cmdPath := checkAtlas() c := exec.Command(cmdPath, "migrate", "apply", "--dir", "file://"+migrationsDir, "--url", db.GetMigrateDSN(), ) out, err := c.CombinedOutput() if err != nil { logger.Errorf("apply migrations failed: %s", out) os.Exit(1) } logger.Infof("apply migrations successfully: %s", out) }, }
View Source
var GenerateCmd = &cobra.Command{ Use: "generate", Short: "generate migrations", Run: func(_ *cobra.Command, _ []string) { ctx := context.Background() dir, err := atlas.NewLocalDir(migrationsDir) if err != nil { logger.Errorf("failed creating atlas migration directory: %v", err) os.Exit(1) } opts := []schema.MigrateOption{ schema.WithDir(dir), schema.WithMigrationMode(schema.ModeInspect), schema.WithDialect(viper.GetString("db.type")), schema.WithDropColumn(true), schema.WithDropIndex(true), schema.WithForeignKeys(false), schema.WithFormatter(atlas.DefaultFormatter), } err = migrate.NamedDiff(ctx, db.GetMigrateDSN(), migrationName, opts...) if err != nil { logger.Fatalf("failed generating migration file: %v", err) os.Exit(1) } logger.Infof("generate migration %s successfully", migrationName) }, }
View Source
var HashCmd = &cobra.Command{ Use: "hash", Short: "update migrations hash", Run: func(_ *cobra.Command, _ []string) { cmdPath := checkAtlas() c := exec.Command(cmdPath, "migrate", "hash", "--dir", "file://"+migrationsDir, ) out, err := c.CombinedOutput() if err != nil { logger.Errorf("update migrations hash failed: %s", out) os.Exit(1) } logger.Infof("update migrations hash successfully") }, }
View Source
var LintCmd = &cobra.Command{ Use: "lint", Short: "lint migrations", Run: func(_ *cobra.Command, _ []string) { cmdPath := checkAtlas() if lintLatest < 1 { lintLatest = 1 } c := exec.Command(cmdPath, "migrate", "lint", "--dev-url", "docker://mysql/8/test", "--dir", "file://"+migrationsDir, "--latest", strconv.Itoa(lintLatest), ) out, err := c.CombinedOutput() if err != nil { logger.Errorf("lint migrations failed: %s", out) os.Exit(1) } logger.Infof("lint migrations successfully") }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.