Skip to content

Commit

Permalink
Merge pull request #101 from gobuffalo/task/migration-create-makr
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed May 18, 2018
2 parents f468a71 + c37d5ef commit b2a29d3
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,28 @@ package pop

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"runtime"
"time"

"github.com/gobuffalo/makr"
"github.com/pkg/errors"
)

// MigrationCreate writes contents for a given migration in normalized files
func MigrationCreate(path, name, ext string, up, down []byte) error {
g := makr.New()
n := time.Now().UTC()
s := n.Format("20060102150405")

err := os.MkdirAll(path, 0766)
if err != nil {
return errors.Wrapf(err, "couldn't create migrations path %s", path)
}

upf := filepath.Join(path, (fmt.Sprintf("%s_%s.up.%s", s, name, ext)))
err = ioutil.WriteFile(upf, up, 0666)
if err != nil {
return errors.Wrapf(err, "couldn't write up migration %s", upf)
}
fmt.Printf("> %s\n", upf)
g.Add(makr.NewFile(upf, string(up)))

downf := filepath.Join(path, (fmt.Sprintf("%s_%s.down.%s", s, name, ext)))
err = ioutil.WriteFile(downf, down, 0666)
if err != nil {
return errors.Wrapf(err, "couldn't write up migration %s", downf)
}
g.Add(makr.NewFile(downf, string(down)))

fmt.Printf("> %s\n", downf)
return nil
return g.Run(".", makr.Data{})
}

// MigrateUp is deprecated, and will be removed in a future version. Use FileMigrator#Up instead.
Expand Down

0 comments on commit b2a29d3

Please sign in to comment.