activerecord-clean-db-structure
activerecord-clean-db-structure copied to clipboard
Consider constraints when sorting columns
The ordering of columns is a great option that we use for a while now. The current implementation however does not take table CONSTRAINTs into account. This results in all CONSTRAINTs to be placed in front of the columns definitions, which is not the PostgreSQL default. And it does not actually sort the CONSTRAINTs since it only sorts based on the first word of the statement.
This PR fixes both issues.
PS: most whitespace correction tools enforce files to end with a single end-of-line character by default. The dump always ends with 2. It is a small issue I also fixed here, but if you like I can place it in a separate PR.
Let me know what you think.
Hi Lukas,
Do you have time to look at this PR? It changes the output structure from:
CREATE TABLE(
CONTRAINT c,
CONTRAINT a,
CONTRAINT b,
column_a,
column_b,
column_c
)
to:
CREATE TABLE(
column_a,
column_b,
column_c,
CONTRAINT a,
CONTRAINT b,
CONTRAINT c
)