Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DownCmd = &cobra.Command{ Use: "down", Short: "Undo a database migration", Long: `Undo a database migration. It is the equivalent of running "sql-migrate down".`, Run: func(cmd *cobra.Command, args []string) { n, err := execMigrations(sqlmigrate.Down) if err != nil { app.App.Logger.Fatal().Err(err).Msg("Failed to apply (down) migrations") } app.App.Logger.Info().Msgf("Successfully applied (down) %d migration(s)!", n) }, }
DownCmd represents the down command
View Source
var RedoCmd = &cobra.Command{ Use: "redo", Short: "Reapply the last migration", Long: `Reapply the last migration. It is the equivalent of running "down" and then "up" as would "sql-migrate redo" do.`, Run: func(cmd *cobra.Command, args []string) { source := sqlmigrate.EmbedFileSystemMigrationSource{ FileSystem: *app.App.MigrationsFS, Root: "migrations/sql/mysql", } migrations, _, err := sqlmigrate.PlanMigration(app.App.Db.DB, string(app.App.Cfg.DatabaseType), source, sqlmigrate.Down, 1) if err != nil { app.App.Logger.Fatal().Err(err).Msg("Failed to reapply migrations") } else if len(migrations) == 0 { app.App.Logger.Info().Msg("Nothing to do!") return } _, err = sqlmigrate.ExecMax(app.App.Db.DB, string(app.App.Cfg.DatabaseType), source, sqlmigrate.Down, 1) if err != nil { app.App.Logger.Fatal().Err(err).Msg("Migration (down) failed") } _, err = sqlmigrate.ExecMax(app.App.Db.DB, string(app.App.Cfg.DatabaseType), source, sqlmigrate.Up, 1) if err != nil { app.App.Logger.Fatal().Err(err).Msg("Migration (up) failed") } app.App.Logger.Info().Msgf("Successfully reapplied migration %s!", migrations[0].Id) }, }
RedoCmd represents the redo command
View Source
var SkipCmd = &cobra.Command{ Use: "skip", Short: "Sets the database level to the most recent version available, without running the migrations", Long: `Sets the database level to the most recent version available, without running the migrations. It is the equivalent of running "sql-migrate skip".`, Run: func(cmd *cobra.Command, args []string) { source := sqlmigrate.EmbedFileSystemMigrationSource{ FileSystem: *app.App.MigrationsFS, Root: "migrations/sql/mysql", } n, err := sqlmigrate.SkipMax(app.App.Db.DB, string(app.App.Cfg.DatabaseType), source, sqlmigrate.Up, limit) if err != nil { app.App.Logger.Fatal().Err(err).Msg("Failed to apply (down) migrations") } switch n { case 0: app.App.Logger.Info().Msg("All migrations have already been applied") case 1: app.App.Logger.Info().Msg("Skipped 1 migration") default: app.App.Logger.Info().Msgf("Skipped %d migrations", n) } }, }
SkipCmd represents the skip command
View Source
var UpCmd = &cobra.Command{ Use: "up", Short: "Migrates the database to the most recent version available", Long: `Migrates the database to the most recent version available. It is the equivalent of running "sql-migrate up".`, Run: func(cmd *cobra.Command, args []string) { n, err := execMigrations(sqlmigrate.Up) if err != nil { app.App.Logger.Fatal().Err(err).Msg("Failed to apply (up) migrations") } app.App.Logger.Info().Msgf("Successfully applied (up) %d migration(s)!", n) }, }
UpCmd represents the up command
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.