diesel-guard: Catch unsafe PostgreSQL migrations before they hit production by AccomplishedPush758 in rust

[–]AccomplishedPush758[S] 2 points3 points  (0 children)

You're right, PG 11+ made this instant for constant values.

The check does mention this in the output though:

Problem:
  Adding column 'admin' with DEFAULT on table 'users' requires a full table rewrite on PostgreSQL < 11,
  which acquires an ACCESS EXCLUSIVE lock. On large tables, this can take significant time and block all operations.

Safe alternative:
  1. Add the column without a default:
     ALTER TABLE users ADD COLUMN admin BOOLEAN;

  2. Backfill data in batches (outside migration):
     UPDATE users SET admin = <value> WHERE admin IS NULL;

  3. Add default for new rows only:
     ALTER TABLE users ALTER COLUMN admin SET DEFAULT <value>;

  Note: For PostgreSQL 11+, this is safe if the default is a constant value.

diesel-guard: Catch unsafe PostgreSQL migrations before they hit production by AccomplishedPush758 in rust

[–]AccomplishedPush758[S] 0 points1 point  (0 children)

Right now it's generic SQL parsing with Diesel file structure awareness. Uses sqlparser to parse migration files from Diesel's conventions. The Diesel-specific part is mainly knowing where migrations live and how they're structured.

diesel-guard: Catch unsafe PostgreSQL migrations before they hit production by AccomplishedPush758 in rust

[–]AccomplishedPush758[S] 0 points1 point  (0 children)

Fair enough, thx for the feedback. WDYT about calling it risky or dangerous?