Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &command.Command{ Name: cmdName, Cobra: &cobra.Command{ Use: cmdName, Short: "Migrate " + buildtime.PROGNAME + " schema", SilenceUsage: true, PreRunE: func(cmd *cobra.Command, args []string) error { return nil }, RunE: func(cmd *cobra.Command, args []string) error { log.Info().Str("cmd", cmdName).Msg("") var config struct { DBConfig db.Config `mapstructure:"db"` } err := viper.Unmarshal(&config) if err != nil { log.Fatal().Err(err).Msg("unable to decode config into struct") } dbPool, err := db.New(config.DBConfig) if err != nil { log.Fatal().Err(err).Msg("unable to create database pool") } if err := dbPool.Ping(); err != nil { return errors.Wrap(err, "unable to ping database") } db, err := dbPool.STDDB() if err != nil { return errors.Wrap(err, "unable to conjur up sql.DB facade") } source, err := bindata.WithInstance( bindata.Resource(migrations.AssetNames(), func(name string) ([]byte, error) { return migrations.Asset(name) })) if err != nil { return errors.Wrap(err, "unable to create migration source") } if err := db.Ping(); err != nil { return errors.Wrap(err, "unable to ping with stdlib driver") } driver, err := postgres.WithInstance(db, &postgres.Config{}) if err != nil { return errors.Wrap(err, "unable to create migration driver") } m, err := migrate.NewWithInstance("file:///migrations/crdb/", source, config.DBConfig.Database, driver) if err != nil { return errors.Wrap(err, "unable to create migration") } if err := m.Down(); err != nil && err != migrate.ErrNoChange { return errors.Wrap(err, "unable to downgrade schema") } if err := m.Up(); err != nil { return errors.Wrap(err, "unable to upgrade schema") } return nil }, }, Setup: func(self *command.Command) error { return db.SetDefaultViperOptions() }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.