Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

psqldef (sqldef)

$ psqldef Official Med Risk
sqldef · Database & Data · MIT · macos / linux / windows

psqldef (part of the sqldef suite alongside mysqldef, sqlite3def, and mssqldef) computes idempotent PostgreSQL DDL diffs between a local schema.sql file and a live database. Supports --export for schema dumps and --dry-run / --check for zero-mutation previews.

FCRS-1.0 Score
86 /100
Good
Medium Confidence
Zero-Friction Install
brew install sqldef/sqldef/psqldef
CLI vs MCP Decision CLI Preferred vs MCP

psqldef reads local schema.sql files via stdin/file flags and computes exact idempotent PostgreSQL DDL diffs locally.

Agent-Readiness Checklist

— JSON Output
— Field Filtering
✓ Non-Interactive
✓ Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 20 / 25

Supports --dry-run, --check (exit code 2 on drift), --export, and stdin piping with deterministic CLI flags, though output is SQL DDL rather than JSON.

  • Built-in --dry-run, --check, and --export flags
  • Outputs SQL DDL text rather than structured JSON
Trust & Safety 23 / 25

Skips destructive DROP statements by default unless --enable-drop is passed, and --dry-run makes pre-flight inspection effortless.

  • Safe-by-default drop suppression without --enable-drop
  • --dry-run previews exact SQL without mutations
Setup & Portability 14 / 15

Single static Go binary available via Homebrew tap, go install, and GitHub releases for macOS, Linux, and Windows.

  • Static Go binary with brew install sqldef/sqldef/psqldef
Utility & Efficiency 13 / 15

Idempotent single-file schema.sql workflow eliminates migration folder bookkeeping for straightforward PostgreSQL schemas.

  • Converges live DB from single declarative schema.sql
Maintenance & Lineage 8 / 10

Actively maintained sqldef/sqldef organization under MIT license with wide production adoption.

  • Maintained at github.com/sqldef/sqldef
Docs & Verifiability 8 / 10

Clear README and command usage examples covering flags, --config, and supported PostgreSQL DDL features.

  • Well-documented flags and examples in sqldef README

Security, Auth & Guardrails

Auth Modes
Env API Key Config File
Credential Storage

Reads PGPASSWORD, PGHOST, PGUSER, PGSSLMODE, or psqldef -h/-U/-W flags; supports YAML config files via --config.

Side Effects
Read-Only Remote Write Destructive
Cost & Quotas

MIT open-source CLI (internal SQL parser under Apache-2.0); completely free.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# psqldef (sqldef) Agent Rules
- Always run `psqldef ... --dry-run < schema.sql` before applying changes.
- Never pass `--enable-drop` without explicit user review of the dry-run DDL output.

Agent-Ready Command Recipes

Safe Read-Only Queries

Export live PostgreSQL schema as DDL
psqldef -h localhost -U postgres mydb --export

Dumps the current database DDL in normalized sqldef format without modifying anything.

Dry-run DDL diff against local schema.sql
psqldef -h localhost -U postgres mydb --dry-run < schema.sql

Prints exact ALTER/CREATE/DROP statements needed to converge without applying them.

Controlled Writes & Previews

Apply idempotent schema diff with drop protection
psqldef -h localhost -U postgres mydb --file schema.sql

Applies non-drop DDL changes to converge the database to schema.sql (skips DROP unless --enable-drop is set).

Strengths for Agents

  • + First-class --dry-run, --check, and --export flags fit CI and agent pre-flight checks.
  • + Suppresses DROP operations by default unless --enable-drop is explicitly provided.
  • + Fast, single Go binary with psql-compatible connection flags and env vars.

Caveats & Pitfalls

  • ! Outputs raw SQL DDL rather than --json diagnostics.
  • ! Advanced PostgreSQL features (custom procedural triggers or complex extensions) may require workarounds outside schema.sql.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI