Adding create command back in

pull/5/head
Josh Fyne 2016-06-29 14:20:34 -04:00
parent 3523b17cdc
commit 7b43a0193d
3 changed files with 34 additions and 2 deletions

View File

@ -57,7 +57,12 @@ func main() {
log.Fatalf("-dbstring=%q: %v\n", dbstring, err) log.Fatalf("-dbstring=%q: %v\n", dbstring, err)
} }
if err := goose.Run(command, db, *dir); err != nil { arguments := []string{*dir}
if len(args) > 3 {
arguments = append(arguments, args[3:]...)
}
if err := goose.Run(command, db, arguments...); err != nil {
log.Fatalf("goose run: %v", err) log.Fatalf("goose run: %v", err)
} }
} }
@ -75,6 +80,7 @@ Examples:
goose postgres "user=postgres dbname=postgres sslmode=disable" up goose postgres "user=postgres dbname=postgres sslmode=disable" up
goose mysql "user:password@/dbname" down goose mysql "user:password@/dbname" down
goose sqlite3 ./foo.db status goose sqlite3 ./foo.db status
goose postgres "user=postgres dbname=postgres sslmode=disable" create init sql
Options: Options:
` `
@ -86,5 +92,6 @@ Commands:
redo Re-run the latest migration redo Re-run the latest migration
status Dump the migration status for the current DB status Dump the migration status for the current DB
dbversion Print the current version of the database dbversion Print the current version of the database
create Creates a blank migration template
` `
) )

18
create.go Normal file
View File

@ -0,0 +1,18 @@
package goose
import (
"database/sql"
"fmt"
"time"
)
// Create writes a new blank migration file.
func Create(db *sql.DB, name, migrationType, dir string) error {
path, err := CreateMigration(name, migrationType, dir, time.Now())
if err != nil {
return err
}
fmt.Println(fmt.Sprintf("Created %s migration at %s", migrationType, path))
return nil
}

View File

@ -5,7 +5,10 @@ import (
"fmt" "fmt"
) )
func Run(command string, db *sql.DB, dir string) error { func Run(command string, db *sql.DB, args ...string) error {
dir := args[0]
additional := args[0:]
switch command { switch command {
case "up": case "up":
if err := Up(db, dir); err != nil { if err := Up(db, dir); err != nil {
@ -15,6 +18,10 @@ func Run(command string, db *sql.DB, dir string) error {
if err := UpByOne(db, dir); err != nil { if err := UpByOne(db, dir); err != nil {
return err return err
} }
case "create":
if err := Create(db, additional[0], additional[1], dir); err != nil {
return err
}
case "down": case "down":
if err := Down(db, dir); err != nil { if err := Down(db, dir); err != nil {
return err return err