stripe / pg-schema-diff

Go library for diffing Postgres schemas and generating SQL migrations
MIT License
366 stars 26 forks source link

Include failed statement's file and line in stderr #167

Closed aleclarson closed 2 months ago

aleclarson commented 2 months ago

Currently, there's no hint as to which statement is failing, at least as far as filename and line number. It'd be awesome to have those!

Navbryce commented 2 months ago

Is this when you're generating the plan?

aleclarson commented 2 months ago

Yes it is. In this case, the error message is syntax-related:

Error: generating plan: getting new schema: running DDL: ERROR: syntax error at or near "%" (SQLSTATE 42601)
bplunkett-stripe commented 2 months ago

That makes sense! I'll try to put up something tomorrow for this. Unfortunately, it probably won't include line number because that would require us to parse the entire SQL AST. When reading in SQL from a file, it's read-in and executed as one large SQL statement and Postgres handles splitting it into individual statements.

Naively splitting on ";" will not work because you can imagine ";" could be present in escaped identifiers, strings, comments.