Improve formatting of dumped schema #436
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Over time, our dumped schema formatting has become less pretty than I would like. Way back in 2016, Caleb and I talked about adopting a SQL formatter for Scenic, but we never found a gem we liked and never took it on ourselves. Enter: niceql.
niceql has zero dependencies of its own, is implemented in a single (large) file, and has over 1.6 million downloads. It has had no releases since November 2022 but I think it's safe to consider it complete rather than abandoned. It's required Ruby version is permissive (
>= 2.5
), so unless there are breaking changes to Ruby basics, I don't think it will be a problem.I've tried it on a few basic views of my own and it produces compact, readable SQL. It's maybe not how I would have formatted things by hand, but it's better than the format we're getting from Postgres. The most common formatter for Postgres is
pgFormatter
but as best I can tell there is no Ruby implementation for it today.In addition to formatting the SQL, this change also adds a newline between
create_view
statements and any indexes associated with the view.Before these changes:
After these changes: