diff --git a/vendor/github.com/pressly/goose/README.md b/vendor/github.com/pressly/goose/README.md index 99633296d..904954643 100644 --- a/vendor/github.com/pressly/goose/README.md +++ b/vendor/github.com/pressly/goose/README.md @@ -42,12 +42,13 @@ Options: directory with migration files (default ".") Commands: - up Migrate the DB to the most recent version available - down Roll back the version by 1 - redo Re-run the latest migration - status Dump the migration status for the current DB - dbversion Print the current version of the database - create Creates a blank migration template + up Migrate the DB to the most recent version available + down Roll back the version by 1 + redo Re-run the latest migration + status Dump the migration status for the current DB + dbversion Print the current version of the database + create Creates a blank migration template + create-next Creates a blank migration template with next sequential version ``` ## create diff --git a/vendor/github.com/pressly/goose/create.go b/vendor/github.com/pressly/goose/create.go index 3ce998f08..afa575f93 100644 --- a/vendor/github.com/pressly/goose/create.go +++ b/vendor/github.com/pressly/goose/create.go @@ -7,8 +7,24 @@ import ( ) // Create writes a new blank migration file. -func Create(db *sql.DB, dir, name, migrationType string) error { - path, err := CreateMigration(name, migrationType, dir, time.Now()) +func Create(db *sql.DB, dir, name, migrationType string, sequential bool) error { + var version string + if !sequential { + version = time.Now().Format("20060102150405") + } else { + m, err := LastMigration(dir) + var last int64 + if err != nil { + if err != ErrNoNextVersion { + return err + } + last = 0; + } else { + last = m.Version + } + version = fmt.Sprintf("%d", last + 1) + } + path, err := CreateMigration(name, migrationType, dir, version) if err != nil { return err } diff --git a/vendor/github.com/pressly/goose/goose.go b/vendor/github.com/pressly/goose/goose.go index 3573a310e..1c9708ef0 100644 --- a/vendor/github.com/pressly/goose/goose.go +++ b/vendor/github.com/pressly/goose/goose.go @@ -44,7 +44,19 @@ func Run(command string, db *sql.DB, dir string, args ...string) error { if len(args) == 2 { migrationType = args[1] } - if err := Create(db, dir, args[0], migrationType); err != nil { + if err := Create(db, dir, args[0], migrationType, false); err != nil { + return err + } + case "create-next": + if len(args) == 0 { + return fmt.Errorf("create must be of form: goose [OPTIONS] DRIVER DBSTRING create-next NAME [go|sql]") + } + + migrationType := "go" + if len(args) == 2 { + migrationType = args[1] + } + if err := Create(db, dir, args[0], migrationType, true); err != nil { return err } case "down": diff --git a/vendor/github.com/pressly/goose/migrate.go b/vendor/github.com/pressly/goose/migrate.go index 3b48007bf..3b862819d 100644 --- a/vendor/github.com/pressly/goose/migrate.go +++ b/vendor/github.com/pressly/goose/migrate.go @@ -147,6 +147,20 @@ func LoadMigrationPlugins(dirpath string) error { return nil } +// lastVersion returns version of last migration present in dirpath +func LastMigration(dirpath string) (*Migration, error) { + ms, err := CollectMigrations(dirpath, 0, MaxVersion) + if err != nil { + return nil, err + } + m, err := ms.Last() + + if err != nil { + return nil, err + } + return m, nil +} + func sortAndConnectMigrations(migrations Migrations) Migrations { sort.Sort(migrations) diff --git a/vendor/github.com/pressly/goose/migration.go b/vendor/github.com/pressly/goose/migration.go index 7d12fcdb5..584fc40d0 100644 --- a/vendor/github.com/pressly/goose/migration.go +++ b/vendor/github.com/pressly/goose/migration.go @@ -104,13 +104,12 @@ func NumericComponent(name string) (int64, error) { return n, e } -func CreateMigration(name, migrationType, dir string, t time.Time) (path string, err error) { +func CreateMigration(name, migrationType, dir string, version string) (path string, err error) { if migrationType != "go" && migrationType != "sql" { return "", errors.New("migration type must be 'go' or 'sql'") } - version := t.Format("20060102150405") filename := fmt.Sprintf("%v_%v.%v", version, name, migrationType) fpath := filepath.Join(dir, filename) diff --git a/vendor/vendor.json b/vendor/vendor.json index 472717e06..ebff576dd 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -356,10 +356,10 @@ "revision": "fb0230561a6ba1cab17beb95f1faedc16584fdb8" }, { - "checksumSHA1": "wlTQrI2jNleFS+jfyfH5o29kvdk=", + "checksumSHA1": "+roVEOcjBhE8Vabfg/a6nTQ5RNE=", "path": "github.com/pressly/goose", - "revision": "31bb74f65b148c79649dc42e4c4bf3948adfb355", - "revisionTime": "2017-03-29T13:44:05Z" + "revision": "ac2d2badf5936328e5d17dc357b29ab8d2814471", + "revisionTime": "2017-03-29T14:11:25Z" }, { "checksumSHA1": "/j0HRFJPThv7HEkZZ/gurf+5fQI=",