-
-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding SQL format checking via pg_format
/ pgFormatter
#3740
Conversation
Awesome! pg_format has a few flags that could make it align more with the current style of most SQL queries in the repo. My preferred params are Some of the queries look uglier now than before, but it should be worth the price. |
I tried out --nogrouping, it only affected a few trigger creation line wraps, so not too necessary. The case one tho, I'm torn, because lower case keywords do look better IMO. I usually prefer to go with the "opinionated defaults" of these formatters, so that people can just run them without any additional config. @Nutomic wanna be the tie-breaker? |
I don't care too much tbh about the specific formatting. It does also have a --config config file format https://github.com/darold/pgFormatter/blob/master/doc/pg_format.conf.sample though it doesn't automatically use a file in the current dir. |
I have no problem with uppercase keywords, it can also make queries a bit easier to read. |
FROM | ||
comment | ||
WHERE | ||
comment.post_id = p.id) AS number_of_comments, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However this kind of formatting isnt good at all. Makes queries almost unreadable with every word on a separate line. Anyway this can be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be able to be tweaked, but I do find it readable. More than anything I'd like to keep the defaults that pg_format
uses, just like we don't tweak prettier or any other formatter.
@phiresky You need to approve this to merge. |
TMP_FILE="/tmp/tmp_pg_format.sql" | ||
pg_format $FILE > $TMP_FILE | ||
diff $FILE $TMP_FILE | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave a comment that this is only used for ci.
taplo format | ||
|
||
# Format sql files | ||
find migrations -type f -name '*.sql' -exec pg_format -i {} + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit confusing to have this formatting stuff in a file named fix-clippy
. Would make sense to rename it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll rename it lint.sh
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. The way the files are found is different in fix-clippy and in the CI script now which might be non-ideal
I'll just get rid of that git-ls to keep them uniform. We don't have any sql files outside there anyway. |
This adds:
fix-clippy.sh
. (pg_format must be installed on your system for that)sql_format_check.sh
that usesdiff
to check the before and after run. (since pg_format has no --check)cc @phiresky