forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from macdabby/master
Make code more maintainable
- Loading branch information
Showing
12 changed files
with
51 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/discovery-digital/goose" | ||
) | ||
|
||
func main() { | ||
goose.Command() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package main | ||
package goose | ||
|
||
import ( | ||
"database/sql" | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
"github.com/pressly/goose" | ||
|
||
// Init DB drivers. | ||
_ "github.com/go-sql-driver/mysql" | ||
_ "github.com/lib/pq" | ||
|
@@ -20,14 +18,14 @@ var ( | |
dir = flags.String("dir", ".", "directory with migration files") | ||
) | ||
|
||
func main() { | ||
func Command() { | ||
flags.Usage = usage | ||
flags.Parse(os.Args[1:]) | ||
|
||
args := flags.Args() | ||
|
||
if len(args) > 1 && args[0] == "create" { | ||
if err := goose.Run("create", nil, *dir, args[1:]...); err != nil { | ||
if err := Run("create", nil, *dir, args[1:]...); err != nil { | ||
log.Fatalf("goose run: %v", err) | ||
} | ||
return | ||
|
@@ -47,23 +45,13 @@ func main() { | |
|
||
switch driver { | ||
case "postgres", "mysql", "sqlite3", "redshift": | ||
if err := goose.SetDialect(driver); err != nil { | ||
if err := SetDialect(driver); err != nil { | ||
log.Fatal(err) | ||
} | ||
default: | ||
log.Fatalf("%q driver not supported\n", driver) | ||
} | ||
|
||
switch dbstring { | ||
case "": | ||
log.Fatalf("-dbstring=%q not supported\n", dbstring) | ||
default: | ||
} | ||
|
||
if driver == "redshift" { | ||
driver = "postgres" | ||
} | ||
|
||
db, err := sql.Open(driver, dbstring) | ||
if err != nil { | ||
log.Fatalf("-dbstring=%q: %v\n", dbstring, err) | ||
|
@@ -74,7 +62,7 @@ func main() { | |
arguments = append(arguments, args[3:]...) | ||
} | ||
|
||
if err := goose.Run(command, db, *dir, arguments...); err != nil { | ||
if err := Run(command, db, *dir, arguments...); err != nil { | ||
log.Fatalf("goose run: %v", err) | ||
} | ||
} | ||
|
@@ -104,6 +92,7 @@ Examples: | |
goose postgres "user=postgres dbname=postgres sslmode=disable" status | ||
goose mysql "user:password@/dbname?parseTime=true" status | ||
goose redshift "postgres://user:[email protected]:5439/db" status | ||
goose tidb "user:password@/dbname?parseTime=true" status | ||
Options: | ||
` | ||
|
@@ -115,6 +104,7 @@ Commands: | |
down Roll back the version by 1 | ||
down-to VERSION Roll back to a specific VERSION | ||
redo Re-run the latest migration | ||
reset Roll back all migrations | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import ( | ||
// Import your migrations directory here | ||
_ "github.com/discovery-digital/goose/examples/go-migrations/migrations" | ||
// In your repo, replace "goose" line above with the path to goose: | ||
"github.com/discovery-digital/goose" | ||
) | ||
|
||
func main() { | ||
goose.Command() | ||
} |
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
examples/go-migrations/00002_rename_root.go → ...igrations/migrations/00002_rename_root.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters