Move to Go modules (#10)
This commit is contained in:
7
vendor/github.com/pressly/goose/.gitignore
generated
vendored
7
vendor/github.com/pressly/goose/.gitignore
generated
vendored
@@ -2,3 +2,10 @@
|
||||
cmd/goose/goose*
|
||||
*.swp
|
||||
*.test
|
||||
|
||||
# Files output by tests
|
||||
bin
|
||||
go.db
|
||||
sql.db
|
||||
|
||||
|
||||
|
10
vendor/github.com/pressly/goose/Makefile
generated
vendored
10
vendor/github.com/pressly/goose/Makefile
generated
vendored
@@ -1,7 +1,9 @@
|
||||
.PHONY: dist
|
||||
dist:
|
||||
@mkdir -p ./bin
|
||||
@rm -f ./bin/*
|
||||
GOOS=darwin GOARCH=amd64 go build -o ./bin/goose-darwin64 ./cmd/goose
|
||||
GOOS=linux GOARCH=amd64 go build -o ./bin/goose-linux64 ./cmd/goose
|
||||
GOOS=linux GOARCH=386 go build -o ./bin/goose-linux386 ./cmd/goose
|
||||
|
||||
GOOS=darwin GOARCH=amd64 go build -o ./bin/goose-darwin64 ./cmd/goose
|
||||
GOOS=linux GOARCH=amd64 go build -o ./bin/goose-linux64 ./cmd/goose
|
||||
GOOS=linux GOARCH=386 go build -o ./bin/goose-linux386 ./cmd/goose
|
||||
GOOS=windows GOARCH=amd64 go build -o ./bin/goose-windows64.exe ./cmd/goose
|
||||
GOOS=windows GOARCH=386 go build -o ./bin/goose-windows386.exe ./cmd/goose
|
||||
|
30
vendor/github.com/pressly/goose/README.md
generated
vendored
30
vendor/github.com/pressly/goose/README.md
generated
vendored
@@ -22,9 +22,7 @@ Goose is a database migration tool. Manage your database schema by creating incr
|
||||
- goose pkg doesn't register any SQL drivers anymore,
|
||||
thus no driver `panic()` conflict within your codebase!
|
||||
- goose pkg doesn't have any vendor dependencies anymore
|
||||
- We encourage using sequential versioning of migration files
|
||||
(rather than timestamps-based versioning) to prevent version
|
||||
mismatch and migration colissions
|
||||
- We use timestamped migrations by default but recommend a hybrid approach of using timestamps in the development process and sequential versions in production.
|
||||
|
||||
# Install
|
||||
|
||||
@@ -32,6 +30,11 @@ Goose is a database migration tool. Manage your database schema by creating incr
|
||||
|
||||
This will install the `goose` binary to your `$GOPATH/bin` directory.
|
||||
|
||||
For a lite version of the binary without DB connection dependent commands, use the exclusive build tags:
|
||||
|
||||
$ go build -tags='no_mysql no_sqlite no_psql' -i -o goose ./cmd/goose
|
||||
|
||||
|
||||
# Usage
|
||||
|
||||
```
|
||||
@@ -51,7 +54,7 @@ Commands:
|
||||
redo Re-run the latest migration
|
||||
status Dump the migration status for the current DB
|
||||
version Print the current version of the database
|
||||
create NAME [sql|go] Creates new migration file with next version
|
||||
create NAME [sql|go] Creates new migration file with the current timestamp
|
||||
|
||||
Options:
|
||||
-dir string
|
||||
@@ -65,29 +68,29 @@ Examples:
|
||||
goose sqlite3 ./foo.db up
|
||||
|
||||
goose postgres "user=postgres dbname=postgres sslmode=disable" status
|
||||
goose mysql "user:password@/dbname" status
|
||||
goose mysql "user:password@/dbname?parseTime=true" status
|
||||
goose redshift "postgres://user:password@qwerty.us-east-1.redshift.amazonaws.com:5439/db" status
|
||||
goose tidb "user:password@/dbname?parseTime=true" status
|
||||
```
|
||||
## create
|
||||
|
||||
Create a new SQL migration.
|
||||
|
||||
$ goose create add_some_column sql
|
||||
$ Created new file: 00001_add_some_column.sql
|
||||
$ Created new file: 20170506082420_add_some_column.sql
|
||||
|
||||
Edit the newly created file to define the behavior of your migration.
|
||||
|
||||
You can also create a Go migration, if you then invoke it with [your own goose binary](#go-migrations):
|
||||
|
||||
$ goose create fetch_user_data go
|
||||
$ Created new file: 00002_fetch_user_data.go
|
||||
$ Created new file: 20170506082421_fetch_user_data.go
|
||||
|
||||
## up
|
||||
|
||||
Apply all available migrations.
|
||||
|
||||
$ goose up
|
||||
$ goose: migrating db environment 'development', current version: 0, target: 3
|
||||
$ OK 001_basics.sql
|
||||
$ OK 002_next.sql
|
||||
$ OK 003_and_again.go
|
||||
@@ -104,7 +107,6 @@ Migrate up to a specific version.
|
||||
Roll back a single migration from the current version.
|
||||
|
||||
$ goose down
|
||||
$ goose: migrating db environment 'development', current version: 3, target: 2
|
||||
$ OK 003_and_again.go
|
||||
|
||||
## down-to
|
||||
@@ -119,9 +121,7 @@ Roll back migrations to a specific version.
|
||||
Roll back the most recently applied migration, then run it again.
|
||||
|
||||
$ goose redo
|
||||
$ goose: migrating db environment 'development', current version: 3, target: 2
|
||||
$ OK 003_and_again.go
|
||||
$ goose: migrating db environment 'development', current version: 2, target: 3
|
||||
$ OK 003_and_again.go
|
||||
|
||||
## status
|
||||
@@ -129,7 +129,6 @@ Roll back the most recently applied migration, then run it again.
|
||||
Print the status of all migrations:
|
||||
|
||||
$ goose status
|
||||
$ goose: status for environment 'development'
|
||||
$ Applied At Migration
|
||||
$ =======================================
|
||||
$ Sun Jan 6 11:25:03 2013 -- 001_basics.sql
|
||||
@@ -240,6 +239,13 @@ func Down(tx *sql.Tx) error {
|
||||
}
|
||||
```
|
||||
|
||||
# Hybrid Versioning
|
||||
Please, read the [versioning problem](https://github.com/pressly/goose/issues/63#issuecomment-428681694) first.
|
||||
|
||||
We strongly recommend adopting a hybrid versioning approach, using both timestamps and sequential numbers. Migrations created during the development process are timestamped and sequential versions are ran on production. We believe this method will prevent the problem of conflicting versions when writing software in a team environment.
|
||||
|
||||
To help you adopt this approach, `create` will use the current timestamp as the migration version. When you're ready to deploy your migrations in a production environment, we also provide a helpful `fix` command to convert your migrations into sequential order, while preserving the timestamp ordering. We recommend running `fix` in the CI pipeline, and only when the migrations are ready for production.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under [MIT License](./LICENSE)
|
||||
|
28
vendor/github.com/pressly/goose/create.go
generated
vendored
28
vendor/github.com/pressly/goose/create.go
generated
vendored
@@ -6,39 +6,39 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Create writes a new blank migration file.
|
||||
func Create(db *sql.DB, dir, name, migrationType string) error {
|
||||
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Initial version.
|
||||
version := "00001"
|
||||
|
||||
if last, err := migrations.Last(); err == nil {
|
||||
version = fmt.Sprintf("%05v", last.Version+1)
|
||||
}
|
||||
|
||||
func CreateWithTemplate(db *sql.DB, dir string, migrationTemplate *template.Template, name, migrationType string) error {
|
||||
version := time.Now().Format(timestampFormat)
|
||||
filename := fmt.Sprintf("%v_%v.%v", version, name, migrationType)
|
||||
|
||||
fpath := filepath.Join(dir, filename)
|
||||
|
||||
tmpl := sqlMigrationTemplate
|
||||
if migrationType == "go" {
|
||||
tmpl = goSQLMigrationTemplate
|
||||
}
|
||||
|
||||
if migrationTemplate != nil {
|
||||
tmpl = migrationTemplate
|
||||
}
|
||||
|
||||
path, err := writeTemplateToFile(fpath, tmpl, version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Created new file: %s\n", path)
|
||||
log.Printf("Created new file: %s\n", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create writes a new blank migration file.
|
||||
func Create(db *sql.DB, dir, name, migrationType string) error {
|
||||
return CreateWithTemplate(db, dir, nil, name, migrationType)
|
||||
}
|
||||
|
||||
func writeTemplateToFile(path string, t *template.Template, version string) (string, error) {
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
return "", fmt.Errorf("failed to create file: %v already exists", path)
|
||||
|
87
vendor/github.com/pressly/goose/dialect.go
generated
vendored
87
vendor/github.com/pressly/goose/dialect.go
generated
vendored
@@ -8,8 +8,9 @@ import (
|
||||
// SQLDialect abstracts the details of specific SQL dialects
|
||||
// for goose's few SQL specific statements
|
||||
type SQLDialect interface {
|
||||
createVersionTableSQL() string // sql string to create the goose_db_version table
|
||||
createVersionTableSQL() string // sql string to create the db version table
|
||||
insertVersionSQL() string // sql string to insert the initial version table row
|
||||
deleteVersionSQL() string // sql string to delete version
|
||||
dbVersionQuery(db *sql.DB) (*sql.Rows, error)
|
||||
}
|
||||
|
||||
@@ -31,6 +32,8 @@ func SetDialect(d string) error {
|
||||
dialect = &Sqlite3Dialect{}
|
||||
case "redshift":
|
||||
dialect = &RedshiftDialect{}
|
||||
case "tidb":
|
||||
dialect = &TiDBDialect{}
|
||||
default:
|
||||
return fmt.Errorf("%q: unknown dialect", d)
|
||||
}
|
||||
@@ -46,21 +49,21 @@ func SetDialect(d string) error {
|
||||
type PostgresDialect struct{}
|
||||
|
||||
func (pg PostgresDialect) createVersionTableSQL() string {
|
||||
return `CREATE TABLE goose_db_version (
|
||||
return fmt.Sprintf(`CREATE TABLE %s (
|
||||
id serial NOT NULL,
|
||||
version_id bigint NOT NULL,
|
||||
is_applied boolean NOT NULL,
|
||||
tstamp timestamp NULL default now(),
|
||||
PRIMARY KEY(id)
|
||||
);`
|
||||
);`, TableName())
|
||||
}
|
||||
|
||||
func (pg PostgresDialect) insertVersionSQL() string {
|
||||
return "INSERT INTO goose_db_version (version_id, is_applied) VALUES ($1, $2);"
|
||||
return fmt.Sprintf("INSERT INTO %s (version_id, is_applied) VALUES ($1, $2);", TableName())
|
||||
}
|
||||
|
||||
func (pg PostgresDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC")
|
||||
rows, err := db.Query(fmt.Sprintf("SELECT version_id, is_applied from %s ORDER BY id DESC", TableName()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -68,6 +71,10 @@ func (pg PostgresDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
return rows, err
|
||||
}
|
||||
|
||||
func (pg PostgresDialect) deleteVersionSQL() string {
|
||||
return fmt.Sprintf("DELETE FROM %s WHERE version_id=$1;", TableName())
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// MySQL
|
||||
////////////////////////////
|
||||
@@ -76,21 +83,21 @@ func (pg PostgresDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
type MySQLDialect struct{}
|
||||
|
||||
func (m MySQLDialect) createVersionTableSQL() string {
|
||||
return `CREATE TABLE goose_db_version (
|
||||
return fmt.Sprintf(`CREATE TABLE %s (
|
||||
id serial NOT NULL,
|
||||
version_id bigint NOT NULL,
|
||||
is_applied boolean NOT NULL,
|
||||
tstamp timestamp NULL default now(),
|
||||
PRIMARY KEY(id)
|
||||
);`
|
||||
);`, TableName())
|
||||
}
|
||||
|
||||
func (m MySQLDialect) insertVersionSQL() string {
|
||||
return "INSERT INTO goose_db_version (version_id, is_applied) VALUES (?, ?);"
|
||||
return fmt.Sprintf("INSERT INTO %s (version_id, is_applied) VALUES (?, ?);", TableName())
|
||||
}
|
||||
|
||||
func (m MySQLDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC")
|
||||
rows, err := db.Query(fmt.Sprintf("SELECT version_id, is_applied from %s ORDER BY id DESC", TableName()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -98,6 +105,10 @@ func (m MySQLDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
return rows, err
|
||||
}
|
||||
|
||||
func (m MySQLDialect) deleteVersionSQL() string {
|
||||
return fmt.Sprintf("DELETE FROM %s WHERE version_id=?;", TableName())
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// sqlite3
|
||||
////////////////////////////
|
||||
@@ -106,20 +117,20 @@ func (m MySQLDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
type Sqlite3Dialect struct{}
|
||||
|
||||
func (m Sqlite3Dialect) createVersionTableSQL() string {
|
||||
return `CREATE TABLE goose_db_version (
|
||||
return fmt.Sprintf(`CREATE TABLE %s (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
version_id INTEGER NOT NULL,
|
||||
is_applied INTEGER NOT NULL,
|
||||
tstamp TIMESTAMP DEFAULT (datetime('now'))
|
||||
);`
|
||||
);`, TableName())
|
||||
}
|
||||
|
||||
func (m Sqlite3Dialect) insertVersionSQL() string {
|
||||
return "INSERT INTO goose_db_version (version_id, is_applied) VALUES (?, ?);"
|
||||
return fmt.Sprintf("INSERT INTO %s (version_id, is_applied) VALUES (?, ?);", TableName())
|
||||
}
|
||||
|
||||
func (m Sqlite3Dialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC")
|
||||
rows, err := db.Query(fmt.Sprintf("SELECT version_id, is_applied from %s ORDER BY id DESC", TableName()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,6 +138,10 @@ func (m Sqlite3Dialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
return rows, err
|
||||
}
|
||||
|
||||
func (m Sqlite3Dialect) deleteVersionSQL() string {
|
||||
return fmt.Sprintf("DELETE FROM %s WHERE version_id=?;", TableName())
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// Redshift
|
||||
////////////////////////////
|
||||
@@ -135,24 +150,62 @@ func (m Sqlite3Dialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
type RedshiftDialect struct{}
|
||||
|
||||
func (rs RedshiftDialect) createVersionTableSQL() string {
|
||||
return `CREATE TABLE goose_db_version (
|
||||
return fmt.Sprintf(`CREATE TABLE %s (
|
||||
id integer NOT NULL identity(1, 1),
|
||||
version_id bigint NOT NULL,
|
||||
is_applied boolean NOT NULL,
|
||||
tstamp timestamp NULL default sysdate,
|
||||
PRIMARY KEY(id)
|
||||
);`
|
||||
);`, TableName())
|
||||
}
|
||||
|
||||
func (rs RedshiftDialect) insertVersionSQL() string {
|
||||
return "INSERT INTO goose_db_version (version_id, is_applied) VALUES ($1, $2);"
|
||||
return fmt.Sprintf("INSERT INTO %s (version_id, is_applied) VALUES ($1, $2);", TableName())
|
||||
}
|
||||
|
||||
func (rs RedshiftDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
rows, err := db.Query("SELECT version_id, is_applied from goose_db_version ORDER BY id DESC")
|
||||
rows, err := db.Query(fmt.Sprintf("SELECT version_id, is_applied from %s ORDER BY id DESC", TableName()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rows, err
|
||||
}
|
||||
|
||||
func (rs RedshiftDialect) deleteVersionSQL() string {
|
||||
return fmt.Sprintf("DELETE FROM %s WHERE version_id=?;", TableName())
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// TiDB
|
||||
////////////////////////////
|
||||
|
||||
// TiDBDialect struct.
|
||||
type TiDBDialect struct{}
|
||||
|
||||
func (m TiDBDialect) createVersionTableSQL() string {
|
||||
return fmt.Sprintf(`CREATE TABLE %s (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE,
|
||||
version_id bigint NOT NULL,
|
||||
is_applied boolean NOT NULL,
|
||||
tstamp timestamp NULL default now(),
|
||||
PRIMARY KEY(id)
|
||||
);`, TableName())
|
||||
}
|
||||
|
||||
func (m TiDBDialect) insertVersionSQL() string {
|
||||
return fmt.Sprintf("INSERT INTO %s (version_id, is_applied) VALUES (?, ?);", TableName())
|
||||
}
|
||||
|
||||
func (m TiDBDialect) dbVersionQuery(db *sql.DB) (*sql.Rows, error) {
|
||||
rows, err := db.Query(fmt.Sprintf("SELECT version_id, is_applied from %s ORDER BY id DESC", TableName()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rows, err
|
||||
}
|
||||
|
||||
func (m TiDBDialect) deleteVersionSQL() string {
|
||||
return fmt.Sprintf("DELETE FROM %s WHERE version_id=?;", TableName())
|
||||
}
|
||||
|
4
vendor/github.com/pressly/goose/down.go
generated
vendored
4
vendor/github.com/pressly/goose/down.go
generated
vendored
@@ -40,12 +40,12 @@ func DownTo(db *sql.DB, dir string, version int64) error {
|
||||
|
||||
current, err := migrations.Current(currentVersion)
|
||||
if err != nil {
|
||||
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
|
||||
log.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
if current.Version <= version {
|
||||
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
|
||||
log.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
46
vendor/github.com/pressly/goose/fix.go
generated
vendored
Normal file
46
vendor/github.com/pressly/goose/fix.go
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
package goose
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Fix(dir string) error {
|
||||
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// split into timestamped and versioned migrations
|
||||
tsMigrations, err := migrations.timestamped()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vMigrations, err := migrations.versioned()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Initial version.
|
||||
version := int64(1)
|
||||
if last, err := vMigrations.Last(); err == nil {
|
||||
version = last.Version + 1
|
||||
}
|
||||
|
||||
// fix filenames by replacing timestamps with sequential versions
|
||||
for _, tsm := range tsMigrations {
|
||||
oldPath := tsm.Source
|
||||
newPath := strings.Replace(oldPath, fmt.Sprintf("%d", tsm.Version), fmt.Sprintf("%05v", version), 1)
|
||||
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("RENAMED %s => %s", filepath.Base(oldPath), filepath.Base(newPath))
|
||||
version++
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
13
vendor/github.com/pressly/goose/goose.go
generated
vendored
13
vendor/github.com/pressly/goose/goose.go
generated
vendored
@@ -7,12 +7,21 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const VERSION = "v2.6.0"
|
||||
|
||||
var (
|
||||
duplicateCheckOnce sync.Once
|
||||
minVersion = int64(0)
|
||||
maxVersion = int64((1 << 63) - 1)
|
||||
timestampFormat = "20060102150405"
|
||||
verbose = false
|
||||
)
|
||||
|
||||
// SetVerbose set the goose verbosity mode
|
||||
func SetVerbose(v bool) {
|
||||
verbose = v
|
||||
}
|
||||
|
||||
// Run runs a goose command.
|
||||
func Run(command string, db *sql.DB, dir string, args ...string) error {
|
||||
switch command {
|
||||
@@ -64,6 +73,10 @@ func Run(command string, db *sql.DB, dir string, args ...string) error {
|
||||
if err := DownTo(db, dir, version); err != nil {
|
||||
return err
|
||||
}
|
||||
case "fix":
|
||||
if err := Fix(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
case "redo":
|
||||
if err := Redo(db, dir); err != nil {
|
||||
return err
|
||||
|
30
vendor/github.com/pressly/goose/log.go
generated
vendored
Normal file
30
vendor/github.com/pressly/goose/log.go
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
package goose
|
||||
|
||||
import (
|
||||
std "log"
|
||||
)
|
||||
|
||||
var log Logger = &stdLogger{}
|
||||
|
||||
// Logger is standart logger interface
|
||||
type Logger interface {
|
||||
Fatal(v ...interface{})
|
||||
Fatalf(format string, v ...interface{})
|
||||
Print(v ...interface{})
|
||||
Println(v ...interface{})
|
||||
Printf(format string, v ...interface{})
|
||||
}
|
||||
|
||||
// SetLogger sets the logger for package output
|
||||
func SetLogger(l Logger) {
|
||||
log = l
|
||||
}
|
||||
|
||||
// stdLogger is a default logger that outputs to a stdlib's log.std logger.
|
||||
type stdLogger struct{}
|
||||
|
||||
func (*stdLogger) Fatal(v ...interface{}) { std.Fatal(v...) }
|
||||
func (*stdLogger) Fatalf(format string, v ...interface{}) { std.Fatalf(format, v...) }
|
||||
func (*stdLogger) Print(v ...interface{}) { std.Print(v...) }
|
||||
func (*stdLogger) Println(v ...interface{}) { std.Println(v...) }
|
||||
func (*stdLogger) Printf(format string, v ...interface{}) { std.Printf(format, v...) }
|
59
vendor/github.com/pressly/goose/migrate.go
generated
vendored
59
vendor/github.com/pressly/goose/migrate.go
generated
vendored
@@ -2,12 +2,14 @@ package goose
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -29,7 +31,7 @@ func (ms Migrations) Len() int { return len(ms) }
|
||||
func (ms Migrations) Swap(i, j int) { ms[i], ms[j] = ms[j], ms[i] }
|
||||
func (ms Migrations) Less(i, j int) bool {
|
||||
if ms[i].Version == ms[j].Version {
|
||||
log.Fatalf("goose: duplicate version %v detected:\n%v\n%v", ms[i].Version, ms[i].Source, ms[j].Source)
|
||||
panic(fmt.Sprintf("goose: duplicate version %v detected:\n%v\n%v", ms[i].Version, ms[i].Source, ms[j].Source))
|
||||
}
|
||||
return ms[i].Version < ms[j].Version
|
||||
}
|
||||
@@ -76,6 +78,43 @@ func (ms Migrations) Last() (*Migration, error) {
|
||||
return ms[len(ms)-1], nil
|
||||
}
|
||||
|
||||
// Versioned gets versioned migrations.
|
||||
func (ms Migrations) versioned() (Migrations, error) {
|
||||
var migrations Migrations
|
||||
|
||||
// assume that the user will never have more than 19700101000000 migrations
|
||||
for _, m := range ms {
|
||||
// parse version as timestmap
|
||||
versionTime, err := time.Parse(timestampFormat, fmt.Sprintf("%d", m.Version))
|
||||
|
||||
if versionTime.Before(time.Unix(0, 0)) || err != nil {
|
||||
migrations = append(migrations, m)
|
||||
}
|
||||
}
|
||||
|
||||
return migrations, nil
|
||||
}
|
||||
|
||||
// Timestamped gets the timestamped migrations.
|
||||
func (ms Migrations) timestamped() (Migrations, error) {
|
||||
var migrations Migrations
|
||||
|
||||
// assume that the user will never have more than 19700101000000 migrations
|
||||
for _, m := range ms {
|
||||
// parse version as timestmap
|
||||
versionTime, err := time.Parse(timestampFormat, fmt.Sprintf("%d", m.Version))
|
||||
if err != nil {
|
||||
// probably not a timestamp
|
||||
continue
|
||||
}
|
||||
|
||||
if versionTime.After(time.Unix(0, 0)) {
|
||||
migrations = append(migrations, m)
|
||||
}
|
||||
}
|
||||
return migrations, nil
|
||||
}
|
||||
|
||||
func (ms Migrations) String() string {
|
||||
str := ""
|
||||
for _, m := range ms {
|
||||
@@ -105,6 +144,10 @@ func AddNamedMigration(filename string, up func(*sql.Tx) error, down func(*sql.T
|
||||
// CollectMigrations returns all the valid looking migration scripts in the
|
||||
// migrations folder and go func registry, and key them by version.
|
||||
func CollectMigrations(dirpath string, current, target int64) (Migrations, error) {
|
||||
if _, err := os.Stat(dirpath); os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("%s directory does not exists", dirpath)
|
||||
}
|
||||
|
||||
var migrations Migrations
|
||||
|
||||
// SQL migration files.
|
||||
@@ -209,7 +252,7 @@ func EnsureDBVersion(db *sql.DB) (int64, error) {
|
||||
for rows.Next() {
|
||||
var row MigrationRecord
|
||||
if err = rows.Scan(&row.VersionID, &row.IsApplied); err != nil {
|
||||
log.Fatal("error scanning rows:", err)
|
||||
return 0, errors.Wrap(err, "failed to scan row")
|
||||
}
|
||||
|
||||
// have we already marked this version to be skipped?
|
||||
@@ -233,11 +276,14 @@ func EnsureDBVersion(db *sql.DB) (int64, error) {
|
||||
// latest version of migration has not been applied.
|
||||
toSkip = append(toSkip, row.VersionID)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return 0, errors.Wrap(err, "failed to get next row")
|
||||
}
|
||||
|
||||
return 0, ErrNoNextVersion
|
||||
}
|
||||
|
||||
// Create the goose_db_version table
|
||||
// Create the db version table
|
||||
// and insert the initial 0 value into it
|
||||
func createVersionTable(db *sql.DB) error {
|
||||
txn, err := db.Begin()
|
||||
@@ -262,8 +308,7 @@ func createVersionTable(db *sql.DB) error {
|
||||
return txn.Commit()
|
||||
}
|
||||
|
||||
// GetDBVersion is a wrapper for EnsureDBVersion for callers that don't already
|
||||
// have their own DB instance
|
||||
// GetDBVersion is an alias for EnsureDBVersion, but returns -1 in error.
|
||||
func GetDBVersion(db *sql.DB) (int64, error) {
|
||||
version, err := EnsureDBVersion(db)
|
||||
if err != nil {
|
||||
|
38
vendor/github.com/pressly/goose/migration.go
generated
vendored
38
vendor/github.com/pressly/goose/migration.go
generated
vendored
@@ -2,13 +2,13 @@ package goose
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// MigrationRecord struct.
|
||||
@@ -38,7 +38,7 @@ func (m *Migration) Up(db *sql.DB) error {
|
||||
if err := m.run(db, true); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("OK ", filepath.Base(m.Source))
|
||||
log.Println("OK ", filepath.Base(m.Source))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func (m *Migration) Down(db *sql.DB) error {
|
||||
if err := m.run(db, false); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("OK ", filepath.Base(m.Source))
|
||||
log.Println("OK ", filepath.Base(m.Source))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -55,16 +55,16 @@ func (m *Migration) run(db *sql.DB, direction bool) error {
|
||||
switch filepath.Ext(m.Source) {
|
||||
case ".sql":
|
||||
if err := runSQLMigration(db, m.Source, m.Version, direction); err != nil {
|
||||
return fmt.Errorf("FAIL %v, quitting migration", err)
|
||||
return errors.Wrapf(err, "failed to run SQL migration %q", filepath.Base(m.Source))
|
||||
}
|
||||
|
||||
case ".go":
|
||||
if !m.Registered {
|
||||
log.Fatalf("failed to apply Go migration %q: Go functions must be registered and built into a custom binary (see https://github.com/pressly/goose/tree/master/examples/go-migrations)", m.Source)
|
||||
return errors.Errorf("failed to run Go migration %q: Go functions must be registered and built into a custom binary (see https://github.com/pressly/goose/tree/master/examples/go-migrations)", m.Source)
|
||||
}
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Fatal("db.Begin: ", err)
|
||||
return errors.Wrap(err, "failed to begin transaction")
|
||||
}
|
||||
|
||||
fn := m.UpFn
|
||||
@@ -74,16 +74,27 @@ func (m *Migration) run(db *sql.DB, direction bool) error {
|
||||
if fn != nil {
|
||||
if err := fn(tx); err != nil {
|
||||
tx.Rollback()
|
||||
log.Fatalf("FAIL %s (%v), quitting migration.", filepath.Base(m.Source), err)
|
||||
return err
|
||||
return errors.Wrapf(err, "failed to run Go migration %q", filepath.Base(m.Source))
|
||||
}
|
||||
}
|
||||
if _, err := tx.Exec(GetDialect().insertVersionSQL(), m.Version, direction); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
||||
if direction {
|
||||
if _, err := tx.Exec(GetDialect().insertVersionSQL(), m.Version, direction); err != nil {
|
||||
tx.Rollback()
|
||||
return errors.Wrap(err, "failed to execute transaction")
|
||||
}
|
||||
} else {
|
||||
if _, err := tx.Exec(GetDialect().deleteVersionSQL(), m.Version); err != nil {
|
||||
tx.Rollback()
|
||||
return errors.Wrap(err, "failed to execute transaction")
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
if err := tx.Commit(); err != nil {
|
||||
return errors.Wrap(err, "failed to commit transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -93,7 +104,6 @@ func (m *Migration) run(db *sql.DB, direction bool) error {
|
||||
// XXX_descriptivename.ext where XXX specifies the version number
|
||||
// and ext specifies the type of migration
|
||||
func NumericComponent(name string) (int64, error) {
|
||||
|
||||
base := filepath.Base(name)
|
||||
|
||||
if ext := filepath.Ext(base); ext != ".go" && ext != ".sql" {
|
||||
|
101
vendor/github.com/pressly/goose/migration_sql.go
generated
vendored
101
vendor/github.com/pressly/goose/migration_sql.go
generated
vendored
@@ -4,20 +4,34 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const sqlCmdPrefix = "-- +goose "
|
||||
const scanBufSize = 4 * 1024 * 1024
|
||||
|
||||
var bufferPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return make([]byte, scanBufSize)
|
||||
},
|
||||
}
|
||||
|
||||
// Checks the line to see if the line has a statement-ending semicolon
|
||||
// or if the line contains a double-dash comment.
|
||||
func endsWithSemicolon(line string) bool {
|
||||
scanBuf := bufferPool.Get().([]byte)
|
||||
defer bufferPool.Put(scanBuf)
|
||||
|
||||
prev := ""
|
||||
scanner := bufio.NewScanner(strings.NewReader(line))
|
||||
scanner.Buffer(scanBuf, scanBufSize)
|
||||
scanner.Split(bufio.ScanWords)
|
||||
|
||||
for scanner.Scan() {
|
||||
@@ -40,9 +54,13 @@ func endsWithSemicolon(line string) bool {
|
||||
// within a statement. For these cases, we provide the explicit annotations
|
||||
// 'StatementBegin' and 'StatementEnd' to allow the script to
|
||||
// tell us to ignore semicolons.
|
||||
func getSQLStatements(r io.Reader, direction bool) (stmts []string, tx bool) {
|
||||
func getSQLStatements(r io.Reader, direction bool) ([]string, bool, error) {
|
||||
var buf bytes.Buffer
|
||||
scanBuf := bufferPool.Get().([]byte)
|
||||
defer bufferPool.Put(scanBuf)
|
||||
|
||||
scanner := bufio.NewScanner(r)
|
||||
scanner.Buffer(scanBuf, scanBufSize)
|
||||
|
||||
// track the count of each section
|
||||
// so we can diagnose scripts with no annotations
|
||||
@@ -52,7 +70,8 @@ func getSQLStatements(r io.Reader, direction bool) (stmts []string, tx bool) {
|
||||
statementEnded := false
|
||||
ignoreSemicolons := false
|
||||
directionIsActive := false
|
||||
tx = true
|
||||
tx := true
|
||||
stmts := []string{}
|
||||
|
||||
for scanner.Scan() {
|
||||
|
||||
@@ -96,7 +115,7 @@ func getSQLStatements(r io.Reader, direction bool) (stmts []string, tx bool) {
|
||||
}
|
||||
|
||||
if _, err := buf.WriteString(line + "\n"); err != nil {
|
||||
log.Fatalf("io err: %v", err)
|
||||
return nil, false, fmt.Errorf("io err: %v", err)
|
||||
}
|
||||
|
||||
// Wrap up the two supported cases: 1) basic with semicolon; 2) psql statement
|
||||
@@ -110,24 +129,23 @@ func getSQLStatements(r io.Reader, direction bool) (stmts []string, tx bool) {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatalf("scanning migration: %v", err)
|
||||
return nil, false, fmt.Errorf("scanning migration: %v", err)
|
||||
}
|
||||
|
||||
// diagnose likely migration script errors
|
||||
if ignoreSemicolons {
|
||||
log.Println("WARNING: saw '-- +goose StatementBegin' with no matching '-- +goose StatementEnd'")
|
||||
return nil, false, fmt.Errorf("parsing migration: saw '-- +goose StatementBegin' with no matching '-- +goose StatementEnd'")
|
||||
}
|
||||
|
||||
if bufferRemaining := strings.TrimSpace(buf.String()); len(bufferRemaining) > 0 {
|
||||
log.Printf("WARNING: Unexpected unfinished SQL query: %s. Missing a semicolon?\n", bufferRemaining)
|
||||
return nil, false, fmt.Errorf("parsing migration: unexpected unfinished SQL query: %s. potential missing semicolon", bufferRemaining)
|
||||
}
|
||||
|
||||
if upSections == 0 && downSections == 0 {
|
||||
log.Fatalf(`ERROR: no Up/Down annotations found, so no statements were executed.
|
||||
See https://bitbucket.org/liamstask/goose/overview for details.`)
|
||||
return nil, false, fmt.Errorf("parsing migration: no Up/Down annotations found, so no statements were executed. See https://bitbucket.org/liamstask/goose/overview for details")
|
||||
}
|
||||
|
||||
return
|
||||
return stmts, tx, nil
|
||||
}
|
||||
|
||||
// Run a migration specified in raw SQL.
|
||||
@@ -138,46 +156,85 @@ func getSQLStatements(r io.Reader, direction bool) (stmts []string, tx bool) {
|
||||
//
|
||||
// All statements following an Up or Down directive are grouped together
|
||||
// until another direction directive is found.
|
||||
func runSQLMigration(db *sql.DB, scriptFile string, v int64, direction bool) error {
|
||||
f, err := os.Open(scriptFile)
|
||||
func runSQLMigration(db *sql.DB, sqlFile string, v int64, direction bool) error {
|
||||
f, err := os.Open(sqlFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return errors.Wrap(err, "failed to open SQL migration file")
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
statements, useTx := getSQLStatements(f, direction)
|
||||
statements, useTx, err := getSQLStatements(f, direction)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if useTx {
|
||||
// TRANSACTION.
|
||||
|
||||
printInfo("Begin transaction\n")
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
errors.Wrap(err, "failed to begin transaction")
|
||||
}
|
||||
|
||||
for _, query := range statements {
|
||||
printInfo("Executing statement: %s\n", clearStatement(query))
|
||||
if _, err = tx.Exec(query); err != nil {
|
||||
printInfo("Rollback transaction\n")
|
||||
tx.Rollback()
|
||||
return err
|
||||
return errors.Wrapf(err, "failed to execute SQL query %q", clearStatement(query))
|
||||
}
|
||||
}
|
||||
if _, err := tx.Exec(GetDialect().insertVersionSQL(), v, direction); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
|
||||
if direction {
|
||||
if _, err := tx.Exec(GetDialect().insertVersionSQL(), v, direction); err != nil {
|
||||
printInfo("Rollback transaction\n")
|
||||
tx.Rollback()
|
||||
return errors.Wrap(err, "failed to insert new goose version")
|
||||
}
|
||||
} else {
|
||||
if _, err := tx.Exec(GetDialect().deleteVersionSQL(), v); err != nil {
|
||||
printInfo("Rollback transaction\n")
|
||||
tx.Rollback()
|
||||
return errors.Wrap(err, "failed to delete goose version")
|
||||
}
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
printInfo("Commit transaction\n")
|
||||
if err := tx.Commit(); err != nil {
|
||||
return errors.Wrap(err, "failed to commit transaction")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NO TRANSACTION.
|
||||
for _, query := range statements {
|
||||
printInfo("Executing statement: %s\n", clearStatement(query))
|
||||
if _, err := db.Exec(query); err != nil {
|
||||
return err
|
||||
return errors.Wrapf(err, "failed to execute SQL query %q", clearStatement(query))
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec(GetDialect().insertVersionSQL(), v, direction); err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "failed to insert new goose version")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printInfo(s string, args ...interface{}) {
|
||||
if verbose {
|
||||
log.Printf(s, args...)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
matchSQLComments = regexp.MustCompile(`(?m)^--.*$[\r\n]*`)
|
||||
matchEmptyLines = regexp.MustCompile(`(?m)^$[\r\n]*`)
|
||||
)
|
||||
|
||||
func clearStatement(s string) string {
|
||||
s = matchSQLComments.ReplaceAllString(s, ``)
|
||||
return matchEmptyLines.ReplaceAllString(s, ``)
|
||||
}
|
||||
|
13
vendor/github.com/pressly/goose/reset.go
generated
vendored
13
vendor/github.com/pressly/goose/reset.go
generated
vendored
@@ -2,19 +2,20 @@ package goose
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"sort"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Reset rolls back all migrations
|
||||
func Reset(db *sql.DB, dir string) error {
|
||||
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "failed to collect migrations")
|
||||
}
|
||||
statuses, err := dbMigrationsStatus(db)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "failed to get status of migrations")
|
||||
}
|
||||
sort.Sort(sort.Reverse(migrations))
|
||||
|
||||
@@ -23,7 +24,7 @@ func Reset(db *sql.DB, dir string) error {
|
||||
continue
|
||||
}
|
||||
if err = migration.Down(db); err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "failed to db-down")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +34,7 @@ func Reset(db *sql.DB, dir string) error {
|
||||
func dbMigrationsStatus(db *sql.DB) (map[int64]bool, error) {
|
||||
rows, err := GetDialect().dbVersionQuery(db)
|
||||
if err != nil {
|
||||
return map[int64]bool{}, createVersionTable(db)
|
||||
return map[int64]bool{}, nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
@@ -45,7 +46,7 @@ func dbMigrationsStatus(db *sql.DB) (map[int64]bool, error) {
|
||||
for rows.Next() {
|
||||
var row MigrationRecord
|
||||
if err = rows.Scan(&row.VersionID, &row.IsApplied); err != nil {
|
||||
log.Fatal("error scanning rows:", err)
|
||||
return nil, errors.Wrap(err, "failed to scan row")
|
||||
}
|
||||
|
||||
if _, ok := result[row.VersionID]; ok {
|
||||
|
31
vendor/github.com/pressly/goose/status.go
generated
vendored
31
vendor/github.com/pressly/goose/status.go
generated
vendored
@@ -3,9 +3,10 @@ package goose
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Status prints the status of all migrations.
|
||||
@@ -13,39 +14,41 @@ func Status(db *sql.DB, dir string) error {
|
||||
// collect all migrations
|
||||
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "failed to collect migrations")
|
||||
}
|
||||
|
||||
// must ensure that the version table exists if we're running on a pristine DB
|
||||
if _, err := EnsureDBVersion(db); err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "failed to ensure DB version")
|
||||
}
|
||||
|
||||
fmt.Println(" Applied At Migration")
|
||||
fmt.Println(" =======================================")
|
||||
log.Println(" Applied At Migration")
|
||||
log.Println(" =======================================")
|
||||
for _, migration := range migrations {
|
||||
printMigrationStatus(db, migration.Version, filepath.Base(migration.Source))
|
||||
if err := printMigrationStatus(db, migration.Version, filepath.Base(migration.Source)); err != nil {
|
||||
return errors.Wrap(err, "failed to print status")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func printMigrationStatus(db *sql.DB, version int64, script string) {
|
||||
var row MigrationRecord
|
||||
q := fmt.Sprintf("SELECT tstamp, is_applied FROM goose_db_version WHERE version_id=%d ORDER BY tstamp DESC LIMIT 1", version)
|
||||
e := db.QueryRow(q).Scan(&row.TStamp, &row.IsApplied)
|
||||
func printMigrationStatus(db *sql.DB, version int64, script string) error {
|
||||
q := fmt.Sprintf("SELECT tstamp, is_applied FROM %s WHERE version_id=%d ORDER BY tstamp DESC LIMIT 1", TableName(), version)
|
||||
|
||||
if e != nil && e != sql.ErrNoRows {
|
||||
log.Fatal(e)
|
||||
var row MigrationRecord
|
||||
err := db.QueryRow(q).Scan(&row.TStamp, &row.IsApplied)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return errors.Wrap(err, "failed to query the latest migration")
|
||||
}
|
||||
|
||||
var appliedAt string
|
||||
|
||||
if row.IsApplied {
|
||||
appliedAt = row.TStamp.Format(time.ANSIC)
|
||||
} else {
|
||||
appliedAt = "Pending"
|
||||
}
|
||||
|
||||
fmt.Printf(" %-24s -- %v\n", appliedAt, script)
|
||||
log.Printf(" %-24s -- %v\n", appliedAt, script)
|
||||
return nil
|
||||
}
|
||||
|
5
vendor/github.com/pressly/goose/up.go
generated
vendored
5
vendor/github.com/pressly/goose/up.go
generated
vendored
@@ -2,7 +2,6 @@ package goose
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// UpTo migrates up to a specific version.
|
||||
@@ -21,7 +20,7 @@ func UpTo(db *sql.DB, dir string, version int64) error {
|
||||
next, err := migrations.Next(current)
|
||||
if err != nil {
|
||||
if err == ErrNoNextVersion {
|
||||
fmt.Printf("goose: no migrations to run. current version: %d\n", current)
|
||||
log.Printf("goose: no migrations to run. current version: %d\n", current)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
@@ -53,7 +52,7 @@ func UpByOne(db *sql.DB, dir string) error {
|
||||
next, err := migrations.Next(currentVersion)
|
||||
if err != nil {
|
||||
if err == ErrNoNextVersion {
|
||||
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
|
||||
log.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
15
vendor/github.com/pressly/goose/version.go
generated
vendored
15
vendor/github.com/pressly/goose/version.go
generated
vendored
@@ -2,7 +2,6 @@ package goose
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Version prints the current version of the database.
|
||||
@@ -12,6 +11,18 @@ func Version(db *sql.DB, dir string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("goose: version %v\n", current)
|
||||
log.Printf("goose: version %v\n", current)
|
||||
return nil
|
||||
}
|
||||
|
||||
var tableName = "goose_db_version"
|
||||
|
||||
// TableName returns goose db version table name
|
||||
func TableName() string {
|
||||
return tableName
|
||||
}
|
||||
|
||||
// SetTableName set goose db version table name
|
||||
func SetTableName(n string) {
|
||||
tableName = n
|
||||
}
|
||||
|
Reference in New Issue
Block a user