Skip to content

Commit b02ee18

Browse files
committed
fix: 正規表現にマッチしなかった時にidを出力する
1 parent 415da4f commit b02ee18

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

migration/migration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ func NewMigration(dir string, id string) Migration {
3232
b, _ := ioutil.ReadFile(dir + "/" + id + ".sql")
3333
r := regexp.MustCompile(`(?m)-- \+migrate Up\n([\s\S]*)\n-- \+migrate Down\n([\s\S]*)`)
3434
sqls := r.FindSubmatch(b)
35+
if len(sqls) == 0 {
36+
log.Fatalf("Invalid file format: %s\n", id)
37+
}
3538
up := splitSQL(string(sqls[1]))
3639
down := splitSQL(string(sqls[2]))
3740
return Migration{ID: id, Up: up, Down: down}

0 commit comments

Comments
 (0)