remove db fix, unexport stuff

pull/120/head
1vn 2018-10-30 17:02:57 -04:00
parent 286883adf5
commit 22d96449ec
4 changed files with 9 additions and 21 deletions

View File

@ -26,8 +26,8 @@ func main() {
args := flags.Args() args := flags.Args()
if len(args) > 1 && args[0] == "create" { if len(args) > 1 && (args[0] == "create" || args[0] == "fix") {
if err := goose.Run("create", nil, *dir, args[1:]...); err != nil { if err := goose.Run(args[0], nil, *dir, args[1:]...); err != nil {
log.Fatalf("goose run: %v", err) log.Fatalf("goose run: %v", err)
} }
return return

20
fix.go
View File

@ -1,25 +1,24 @@
package goose package goose
import ( import (
"database/sql"
"fmt" "fmt"
"os" "os"
"strings" "strings"
) )
func Fix(db *sql.DB, dir string) error { func Fix(dir string) error {
migrations, err := CollectMigrations(dir, minVersion, maxVersion) migrations, err := CollectMigrations(dir, minVersion, maxVersion)
if err != nil { if err != nil {
return err return err
} }
// split into timestamped and versioned migrations // split into timestamped and versioned migrations
tsMigrations, err := migrations.Timestamped() tsMigrations, err := migrations.timestamped()
if err != nil { if err != nil {
return err return err
} }
vMigrations, err := migrations.Versioned() vMigrations, err := migrations.versioned()
if err != nil { if err != nil {
return err return err
} }
@ -29,12 +28,6 @@ func Fix(db *sql.DB, dir string) error {
version = last.Version + 1 version = last.Version + 1
} }
// fix db table as well
tx, err := db.Begin()
if err != nil {
log.Fatal("db.Begin: ", err)
}
// fix filenames by replacing timestamps with sequential versions // fix filenames by replacing timestamps with sequential versions
for _, tsm := range tsMigrations { for _, tsm := range tsMigrations {
oldPath := tsm.Source oldPath := tsm.Source
@ -44,13 +37,8 @@ func Fix(db *sql.DB, dir string) error {
return err return err
} }
if _, err := tx.Exec(GetDialect().updateVersionSQL(), version, tsm.Version); err != nil {
tx.Rollback()
return err
}
version++ version++
} }
return tx.Commit() return nil
} }

View File

@ -66,7 +66,7 @@ func Run(command string, db *sql.DB, dir string, args ...string) error {
return err return err
} }
case "fix": case "fix":
if err := Fix(db, dir); err != nil { if err := Fix(dir); err != nil {
return err return err
} }
case "redo": case "redo":

View File

@ -78,7 +78,7 @@ func (ms Migrations) Last() (*Migration, error) {
} }
// Versioned gets versioned migrations. // Versioned gets versioned migrations.
func (ms Migrations) Versioned() (Migrations, error) { func (ms Migrations) versioned() (Migrations, error) {
var migrations Migrations var migrations Migrations
// assume that the user will never have more than 19700101000000 migrations // assume that the user will never have more than 19700101000000 migrations
@ -95,7 +95,7 @@ func (ms Migrations) Versioned() (Migrations, error) {
} }
// Timestamped gets the timestamped migrations. // Timestamped gets the timestamped migrations.
func (ms Migrations) Timestamped() (Migrations, error) { func (ms Migrations) timestamped() (Migrations, error) {
var migrations Migrations var migrations Migrations
// assume that the user will never have more than 19700101000000 migrations // assume that the user will never have more than 19700101000000 migrations