vendor dependencies with dep
This commit is contained in:
parent
93d8310491
commit
1384296a47
2712 changed files with 965742 additions and 0 deletions
57
vendor/github.com/go-pg/migrations/example/main.go
generated
vendored
Normal file
57
vendor/github.com/go-pg/migrations/example/main.go
generated
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-pg/migrations"
|
||||
"github.com/go-pg/pg"
|
||||
)
|
||||
|
||||
const usageText = `This program runs command on the db. Supported commands are:
|
||||
- init - creates gopg_migrations table.
|
||||
- up - runs all available migrations.
|
||||
- down - reverts last migration.
|
||||
- reset - reverts all migrations.
|
||||
- version - prints current db version.
|
||||
- set_version [version] - sets db version without running migrations.
|
||||
|
||||
Usage:
|
||||
go run *.go <command> [args]
|
||||
`
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
db := pg.Connect(&pg.Options{
|
||||
User: "postgres",
|
||||
Database: "pg_migrations_example",
|
||||
})
|
||||
|
||||
oldVersion, newVersion, err := migrations.Run(db, flag.Args()...)
|
||||
if err != nil {
|
||||
exitf(err.Error())
|
||||
}
|
||||
if newVersion != oldVersion {
|
||||
fmt.Printf("migrated from version %d to %d\n", oldVersion, newVersion)
|
||||
} else {
|
||||
fmt.Printf("version is %d\n", oldVersion)
|
||||
}
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Printf(usageText)
|
||||
flag.PrintDefaults()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func errorf(s string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, s+"\n", args...)
|
||||
}
|
||||
|
||||
func exitf(s string, args ...interface{}) {
|
||||
errorf(s, args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue