Skip to content

Commit

Permalink
fix error when absolute path is provied in 'pgmigrate new --migration…
Browse files Browse the repository at this point in the history
…s' (#2)

A possible fix for #1.
Not sure why we need `filepath.Rel` at all.
`os.WriteFile` works with both absolute and relative paths, so user can
provide either and it should work out of the box.

Smoke test after the fix:
```
 ./main new --migrations $(pwd)/example/migrations
INFO created id=00004_generated path=/Users/vvkh/Projects/pgmigrate/example/migrations/00004_generated.sql

./main new --migrations example/migrations 
INFO created id=00004_generated path=example/migrations/00004_generated.sql
```
  • Loading branch information
vvkh authored Aug 31, 2023
1 parent 4f90829 commit 655a7cf
Showing 1 changed file with 0 additions and 5 deletions.
5 changes: 0 additions & 5 deletions cmd/pgmigrate/root/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"

Expand Down Expand Up @@ -120,10 +119,6 @@ pgmigrate new vim_user_example --create --bare | xargs vim
id := fmt.Sprintf("%s_%s", prefix, suffix)
filename := fmt.Sprintf("%s.sql", id)
fp := path.Join(dir, filename)
fp, err = filepath.Rel(".", fp)
if err != nil {
return err
}
if *NewFlags.Create {
if err := os.WriteFile(fp, []byte(`-- write your migration here`), 0o660); err != nil {
return err
Expand Down

0 comments on commit 655a7cf

Please sign in to comment.