Handling spaces in front of the goose command
We had an extra space at the beginning of the file, i.e.
-- +goose Up
SET SCHEMA 'public'
...
The migration was noticed but goose did nothing, no error message. It seemed to treat the migration as if it were empty.
Is there a way to populate error on such scenarios? Is there a linter check available?
Thanks in advance!
I'll add this to parser logic I'm working on.
https://github.com/pressly/goose/pull/385
By linter, do you mean something like a goose verify command that runs against your migration folder to verify all migrations files are valid?
Would something like https://github.com/pressly/goose/issues/448 be helpful?
I've been using this to catch malformed migration files but figured it may be useful for others.
Fwiw, with the recent changes in #446 you should see a failure similar to:
unexpected error: failed to parse migration: unexpected state 0 on line "CREATE TABLE emp (", see https://github.com/pressly/goose#sql-migrations
It means the parser wasn't able to find a valid -- +goose Up annotation (because we're strictly looking for the line to have no trailing spaces).
Having said that, I think we can catch some of these common errors and report a better message.
Hi @mfridman,
Yes, goose verify would be perfect as it helps to detect malformed migrations way earlier and can be integrated into the CI flows.
Having said that, I think we can catch some of these common errors and report a better message.
Yes, this would be helpful as well.
Hey @rajeshkarnena, we’ve take a few steps towards mitigating such issues.
In https://github.com/pressly/goose/issues/448 we added a goose validate command that can be used to validate files ahead of time, such as in CI.
The SQL parser logic has also been improved, so those errors you pointed out should be caught much earlier.
Lastly, there’s a blog post that goes into a bit more detail on the structure of .sql files.
https://pressly.github.io/goose/blog/2022/overview-sql-file/
Hope this helps, going to close the issue. But feel free to file another issue if you encounter any further issues.