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

Configuration

Create a diesel-guard.toml file in your project root to customize behavior.

Initialize

Generate a documented configuration file:

diesel-guard init

Use --force to overwrite an existing file:

diesel-guard init --force

All Options

# Framework configuration (REQUIRED)
# Specify which migration framework you're using
# Valid values: "diesel" or "sqlx"
framework = "diesel"

# Skip migrations before this timestamp
# Accepts: YYYYMMDDHHMMSS, YYYY_MM_DD_HHMMSS, or YYYY-MM-DD-HHMMSS
# Works with any migration directory format
start_after = "2024_01_01_000000"

# Also check down.sql files (default: false)
check_down = true

# Disable specific checks (blacklist)
disable_checks = ["AddColumnCheck"]

# Run only specific checks (whitelist). Cannot be used with disable_checks.
enable_checks = ["AddIndexCheck", "AddNotNullCheck"]

# Directory containing custom Rhai check scripts
custom_checks_dir = "checks"

# Target Postgres major version.
# When set, version-aware checks adjust their behavior accordingly.
# Example: setting 11 allows ADD COLUMN with constant DEFAULT (safe on PG 11+),
# but still warns for volatile defaults like DEFAULT now() on all versions.
postgres_version = 16

Available Check Names

Use these names in disable_checks (blacklist) or enable_checks (whitelist):

Check NameOperation
AddColumnCheckADD COLUMN with DEFAULT
AddIndexCheckCREATE INDEX without CONCURRENTLY
AddJsonColumnCheckADD COLUMN with JSON type
AddNotNullCheckALTER COLUMN SET NOT NULL
AddPrimaryKeyCheckADD PRIMARY KEY to existing table
AddSerialColumnCheckADD COLUMN with SERIAL
AddUniqueConstraintCheckADD UNIQUE constraint via ALTER TABLE
AlterColumnTypeCheckALTER COLUMN TYPE
CharTypeCheckCHAR/CHARACTER column types
CreateExtensionCheckCREATE EXTENSION
DropColumnCheckDROP COLUMN
DropDatabaseCheckDROP DATABASE
DropIndexCheckDROP INDEX without CONCURRENTLY
DropPrimaryKeyCheckDROP PRIMARY KEY
DropTableCheckDROP TABLE
GeneratedColumnCheckADD COLUMN with GENERATED STORED
ReindexCheckREINDEX without CONCURRENTLY
RenameColumnCheckRENAME COLUMN
RenameTableCheckRENAME TABLE
ShortIntegerPrimaryKeyCheckSMALLINT/INT/INTEGER primary keys
TimestampTypeCheckTIMESTAMP without time zone
TruncateTableCheckTRUNCATE TABLE
UnnamedConstraintCheckUnnamed constraints (UNIQUE, FOREIGN KEY, CHECK)
WideIndexCheckIndexes with 4+ columns

Custom check names are the filename stem of the .rhai file (e.g., require_concurrent_index.rhairequire_concurrent_index).