Closed davidmdm closed 2 years ago
@jackc
I didn't want to change anything or cause any tests to break, so I added the Filename
property only, so that it could be used by programs that use tern/migrate
.
Would you be open to changing the MigrationPgError Error to something like this?
type MigrationPgError struct {
Filename string
Sql string
*pgconn.PgError
}
func (e MigrationPgError) Error() string {
if e.Filename == "" {
return e.PgError.Error()
}
return fmt.Sprintf("%s: %s", e.Filename, e.PgError.Error())
}
While migrations typically do come from files it isn't strictly required, so I would suggest that instead of Filename
the field should be named Name
or MigrationName
.
As far as changing MigrationPgError.Error()
, I think that is okay as long we can keep the existing error output for the CLI tool.
@jackc
Here is what I did in this last commit:
Filename
-> MigrationName
Error() string
method for MigrationPgError that included MigrationName in outputUnwrap() error
method for MigrationPgError is someone wants to get the PgError directly.LGTM
@jackc
Can you tag master with this new commit? I want to use this new error context in my tern scripts.
Much appreciated :)
Done.
Simply put, when using
tern/migrate
to run migrations, if a migration fails the error is returned and the PgError message is printed to the user. It would be useful to show to the user which of their migration files caused the error.Intended use: