migrate icon indicating copy to clipboard operation
migrate copied to clipboard

'migrate create' will generate filenames that cannot be parsed

Open coolaj86 opened this issue 3 years ago • 1 comments

Describe the Bug

migrate create allows you to generate filenames that cannot be parsed

Steps to Reproduce

Use migrate create to create a migration:

my_name="init"

go run -tags 'postgres' -- \
    github.com/golang-migrate/migrate/v4/cmd/migrate create \
        -dir ./migrations/
        -tz 'America/Denver'
        -format '2006-01-02_15-04-05-0700'
        -ext sql "$my_name"
migrations/2022-04-21_16-26-25-0600_init.up.sql
migrations/2022-04-21_16-26-25-0600_init.down.sql

Try to run the migration:

go run -tags 'postgres' -- \
    github.com/golang-migrate/migrate/v4/cmd/migrate
        -source file://migrations/ \
        -database "$DB_URL" \
        up
error: first .: file does not exist

Expected Behavior

  1. Error out when -format <date string> will generate a filename that can't be parsed
  2. Accept the same -format with up as can be used with create

Migrate Version

v4.15.1

Loaded Source Drivers

N/A (file)

Loaded Database Drivers

postgres

Go Version

go version go1.18.1 darwin/amd64

coolaj86 avatar Apr 21 '22 23:04 coolaj86

Since you're using a custom time format that's incompatible with the default one, you'll also need to use a custom parser or regex

dhui avatar May 05 '22 23:05 dhui