12345678910111213141516171819202122232425262728293031323334353637383940 |
- package main
- import (
- "code.osinet.fr/fgm/kurz/infrastructure"
- "os"
- _ "code.osinet.fr/fgm/kurz/migrations"
- "github.com/pressly/goose"
- "github.com/spf13/cobra"
- )
- var cmdMigrateUpTo = &cobra.Command{
- Args: migrateVersionValidator,
- Long: "Migrate the Kurz schema to the most recent version available. Kurz version of 'goose up'.",
- Run: migrateUpToHandler,
- Short: "Migrate to latest version",
- Use: "up-to <version>",
- }
- func init() {
- cmdMigrate.AddCommand(cmdMigrateUpTo)
- }
- // migrateUpToHandler implements the "kurzd migrate up-to" command.
- func migrateUpToHandler(cmd *cobra.Command, args []string) {
- dbDriver, dbDsn := infrastructure.ParseDbCred()
- db, err := infrastructure.DbDial(dbDriver, dbDsn)
- if err != nil {
- panic(err)
- }
- defer db.Close()
- cwd, err := os.Getwd()
- if err != nil {
- panic(err)
- }
- goose.SetDialect(dbDriver)
- goose.UpTo(db, cwd, migrateTargetVersion)
- }
|