Skip to content

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

Open
cabello wants to merge 2 commits intosbdchd:masterfrom
cabello:feat/require-enum-value-ordering
Open

linter: add require-enum-value-ordering rule#992
cabello wants to merge 2 commits intosbdchd:masterfrom
cabello:feat/require-enum-value-ordering

Conversation

@cabello
Copy link

@cabello cabello commented Mar 8, 2026

Summary

  • 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 levels, etc.
  • Includes documentation and 7 tests covering error and OK cases

Test plan

  • cargo test -p squawk-linter require_enum_value_ordering — all 7 tests pass
  • cargo test -p squawk-linter — full suite (261 tests) passes
  • Verify rule triggers on real migration files with ALTER TYPE ... ADD VALUE without BEFORE/AFTER

🤖 Generated with Claude Code

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 cc74755

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cabello
Copy link
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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants