Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Linter for dangerous Postgres migration patterns in Diesel and SQLx. Prevents downtime caused by unsafe schema changes.

✓ Detects operations that lock tables or cause downtime
✓ Provides safe alternatives for each blocking operation
✓ Works with both Diesel and SQLx migration frameworks
✓ Supports safety-assured blocks for verified operations
✓ Extensible with custom checks

⭐ If this looks useful, a star on GitHub helps more developers find it.

How It Works

diesel-guard analyzes your migration SQL using Postgres’s own parser (pg_query via libpg_query) and checks each statement against a set of safety rules. When it finds a potentially dangerous operation, it reports:

  • The operation — what SQL was detected
  • The problem — what lock it acquires, why it’s dangerous, and under what conditions
  • A safe alternative — a step-by-step approach that achieves the same goal without the risk