rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.19k stars 275 forks source link

How can I have a better error description? #52

Open pedrolvr opened 7 years ago

pedrolvr commented 7 years ago

For example, I had this error: pq: column "id" referenced in foreign key constraint does not exist handling 0.sql

rkintzi commented 7 years ago

I got even more verbose error message: ERROR: The last statement must be ended by a semicolon or '-- +migrate StatementEnd' marker.

I have dozen of migrations and don't know which one is failing. Even worse - all them used to work before. Please, do not introduce braking changes without providing good error messages.

rubenv commented 7 years ago

@rkintzi This new error is caused by #53 and is meant to guard you from errors. It's not breakage in that it breaks your code, it now just forbids code that was already broken (and might have gone unnoticed). If you have a better solution to this problem, feel free to join in. Always happy to find a better approach.

I do agree that we should at least mention which migration causes that error. Have a look at TxError as an example on how we decorate error messages with filenames. We should probably add something like that in the parsing stage.


@phenrigomes What would you like to see improved in that error message? As far as I can tell it states that in your 0.sql migration there's a column "id" referenced in foreign key constraint does not exist, which means you have a foreign key pointing to a column that does not exist (yet?). Not sure how to improve on that (it's the error context we get from PostgreSQL).

rkintzi commented 7 years ago

@rubenv It seems that the problem is caused by empty reverse migrations. If there is no reverse migration (no -- +migrate Down marker) no error is reported. If there is a marker, but no sql statement below it, an error is reported.

kandeshvari commented 6 years ago

My problem was in SQL commented strings before -- +migrate Down string. I've removed those comments and problem was solved.