Skip to content

linter: add require-enum-value-ordering rule#992

Merged
sbdchd merged 7 commits intosbdchd:masterfrom
cabello:feat/require-enum-value-ordering
Mar 10, 2026
Merged

linter: add require-enum-value-ordering rule#992
sbdchd merged 7 commits intosbdchd:masterfrom
cabello:feat/require-enum-value-ordering

Conversation

@cabello
Copy link
Contributor

@cabello cabello commented Mar 8, 2026

Adds a new lint rule require-enum-value-ordering that flags ALTER TYPE ... ADD VALUE statements missing BEFORE or AFTER.

Without explicit ordering, new enum values are silently appended to the end, which can cause unexpected ordering in status workflows, severity, priority, etc.

Add a new lint rule that flags ALTER TYPE ... ADD VALUE statements
missing BEFORE or AFTER, which silently append to the end of the enum
and can cause unexpected ordering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@netlify
Copy link

netlify bot commented Mar 8, 2026

👷 Deploy request for squawkhq pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d79aac1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cabello
Copy link
Contributor Author

cabello commented Mar 8, 2026

Hi 👋
We have our own migration system https://github.com/marcduez/pg-migrate and we want as much as possible for db migrations to be idempotent, safe and aligned, and we noticed that if two developers touch the same enum we might end up with a distinct set of schema dump depending on the order they run each migration.
Thank you for considering this change 🙇

@sbdchd
Copy link
Owner

sbdchd commented Mar 8, 2026

Cool rule, thank you for putting this together!

I was curious how Django handles this, but turns out they don't support Postgres enum types unfortunately.

For the docs, I think it might be helpful to show the query pattern aka the select query you're making that depends on the ordering. Do you have an example?

@cabello
Copy link
Contributor Author

cabello commented Mar 9, 2026

Thank you for the reply, we don't use ORMs so we try to benefit to all features the database has datatypes, triggers, materialized views, etc.

It's the output of a pg_dump of the database, we commit that to git so CI can break if it changes after running migrations; it includes enum creation and internally Postgres must use some tinyint to represent that, it's not trivial to manipulate enums in Postgres.

If dev A dumps the schema, commits and the values were A B C then the CI runs it and due to the order of execution the values are A C B, then that dev has to find a way to sync with master otherwise they will always be reverting that change.

kodiakhq bot pushed a commit that referenced this pull request Mar 9, 2026
@sbdchd sbdchd added the automerge automerge with kodiak label Mar 10, 2026
@sbdchd sbdchd merged commit a40fb38 into sbdchd:master Mar 10, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge automerge with kodiak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants