r/PostgreSQL • • 2d ago

Tools A Django migration linter that flags non-concurrent indexes, table rewrites and long locks

I maintain django-safe-migrations, a static linter for Django migrations. 0.8.0 came out today. I'm posting here because most of its rules are about what PostgreSQL actually does when Django runs a migration:

  • CREATE INDEX / DROP INDEX without CONCURRENTLY, and the reminder that concurrent operations need atomic = False
  • adding a foreign key or CHECK constraint without NOT VALID, which checks every existing row while holding a lock
  • unique constraints built without a concurrent index
  • shrinking a VARCHAR, which rewrites the table
  • ALTER TYPE ... ADD VALUE inside a transaction: the new enum value can't be used before commit
  • DDL in RunSQL without SET lock_timeout

It only reads the migration files, so it runs in CI without a database, and each finding comes with the safer pattern.

GitHub: https://github.com/YasserShkeir/django-safe-migrations

Which Postgres-side patterns would you want a linter like this to catch?

3 Upvotes

6 comments sorted by

1

u/Discordbothost 1d ago

If ADD CONSTRAINT and VALIDATE run in one transaction, the stronger lock stays held through the scan. I'd flag that pair and suggest splitting it across two migrations.

0

u/AutoModerator 2d ago

AI Policy:

Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.

Mod decisions will be based on the quality of the content, not who or what generated it.

Sub Resources:

Youtube Channel

Free Postgres Webinars and Workshops

Discord: People, Postgres, Data

Join us, we have cookies and nice people.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.