mirror of https://github.com/pressly/goose.git
Actually works now, re-added go migration template, updated cmd parser
parent
e4c7697123
commit
15b7bf5fc7
cmd/goose
|
@ -25,7 +25,7 @@ func main() {
|
||||||
flags.Parse(os.Args[1:])
|
flags.Parse(os.Args[1:])
|
||||||
|
|
||||||
args := flags.Args()
|
args := flags.Args()
|
||||||
if len(args) != 3 {
|
if len(args) < 3 {
|
||||||
flags.Usage()
|
flags.Usage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
24
migrate.go
24
migrate.go
|
@ -393,6 +393,9 @@ func CreateMigration(name, migrationType, dir string, t time.Time) (path string,
|
||||||
|
|
||||||
fpath := filepath.Join(dir, filename)
|
fpath := filepath.Join(dir, filename)
|
||||||
tmpl := sqlMigrationTemplate
|
tmpl := sqlMigrationTemplate
|
||||||
|
if migrationType == "go" {
|
||||||
|
tmpl = goSqlMigrationTemplate
|
||||||
|
}
|
||||||
|
|
||||||
path, err = writeTemplateToFile(fpath, tmpl, timestamp)
|
path, err = writeTemplateToFile(fpath, tmpl, timestamp)
|
||||||
|
|
||||||
|
@ -422,3 +425,24 @@ var sqlMigrationTemplate = template.Must(template.New("goose.sql-migration").Par
|
||||||
-- SQL section 'Down' is executed when this migration is rolled back
|
-- SQL section 'Down' is executed when this migration is rolled back
|
||||||
|
|
||||||
`))
|
`))
|
||||||
|
var goSqlMigrationTemplate = template.Must(template.New("goose.go-migration").Parse(`
|
||||||
|
package migration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/pressly/goose"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
goose.AddMigration(Up_{{.}}, Down_{{.}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Up_{{.}}(tx *sql.Tx) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Down_{{.}}(tx *sql.Tx) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
`))
|
||||||
|
|
Loading…
Reference in New Issue