sbdchd / squawk

🐘 linter for PostgreSQL, focused on migrations
https://squawkhq.com
GNU General Public License v3.0
541 stars 37 forks source link

`constraint-missing-not-valid` should also forbid constraints when adding a column #314

Open avoronov-box opened 11 months ago

avoronov-box commented 11 months ago

Adding a column with a constraint directly causes the same locking issue as adding a constraint:

ALTER TABLE "some_table" ADD COLUMN "some_field" integer NULL CHECK ("some_field" >= 0);

Currently squawk does not report this as a violation. Would be great to catch this.

chdsbd commented 11 months ago

I believe this is okay, there will be some locking when modify a table schema in Postgres. I think as long as the locking is short, it will be okay for a production system.

When adding a null field, Postgres will take almost no time to verify the check constraint, because there aren't any rows with the new column

There's some docs on safely applying migrations to prevent locks from breaking a running application: https://squawkhq.com/docs/safe_migrations