{"id":36344349,"url":"https://github.com/ayarotsky/diesel-guard","last_synced_at":"2026-04-11T18:18:21.131Z","repository":{"id":326727270,"uuid":"1106385392","full_name":"ayarotsky/diesel-guard","owner":"ayarotsky","description":"Catch dangerous PostgreSQL migrations in Diesel before they take down production","archived":false,"fork":false,"pushed_at":"2026-01-05T17:40:14.000Z","size":226,"stargazers_count":67,"open_issues_count":2,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-11T19:35:43.639Z","etag":null,"topics":["diesel-rs","linter","postgresql","rust","zero-downtime"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/diesel-guard","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ayarotsky.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-11-29T06:19:44.000Z","updated_at":"2026-01-09T07:01:04.000Z","dependencies_parsed_at":"2025-12-29T08:02:42.526Z","dependency_job_id":null,"html_url":"https://github.com/ayarotsky/diesel-guard","commit_stats":null,"previous_names":["ayarotsky/diesel-guard"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ayarotsky/diesel-guard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayarotsky%2Fdiesel-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayarotsky%2Fdiesel-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayarotsky%2Fdiesel-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayarotsky%2Fdiesel-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayarotsky","download_url":"https://codeload.github.com/ayarotsky/diesel-guard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayarotsky%2Fdiesel-guard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28385633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T12:01:30.995Z","status":"ssl_error","status_checked_at":"2026-01-13T12:00:09.625Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diesel-rs","linter","postgresql","rust","zero-downtime"],"created_at":"2026-01-11T13:00:32.127Z","updated_at":"2026-04-11T18:18:21.123Z","avatar_url":"https://github.com/ayarotsky.png","language":"Rust","funding_links":[],"categories":["Multiple languages","Libraries","Utilities","CLI","Rust"],"sub_categories":["Database"],"readme":"# Diesel Guard 🐘💨\n\n![Build Status](https://github.com/ayarotsky/diesel-guard/actions/workflows/ci.yml/badge.svg?branch=main) [![crates.io](https://img.shields.io/crates/v/diesel-guard)](https://crates.io/crates/diesel-guard) [![docs](https://img.shields.io/badge/docs-documentation-blue)](https://ayarotsky.github.io/diesel-guard/) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![codecov](https://codecov.io/github/ayarotsky/diesel-guard/graph/badge.svg?token=YCBD10IGNU)](https://codecov.io/github/ayarotsky/diesel-guard)\n\n**Linter for dangerous Postgres migration patterns in Diesel and SQLx. Prevents downtime caused by unsafe schema changes.**\n\n![demo](demo.gif)\n\n✓ Detects operations that lock tables or cause downtime\u003cbr\u003e\n✓ Provides safe alternatives for each blocking operation\u003cbr\u003e\n✓ Works with both Diesel and SQLx migration frameworks\u003cbr\u003e\n✓ Supports safety-assured blocks for verified operations\u003cbr\u003e\n✓ Extensible with custom checks\u003cbr\u003e\n\n## Why diesel-guard?\n\n**Uses PostgreSQL's own parser.** diesel-guard embeds libpg_query — the C library\ncompiled into Postgres itself. What diesel-guard flags is exactly what Postgres sees.\nIf your SQL has a syntax error, diesel-guard reports that too.\n\n**Scriptable custom checks.** Write project-specific rules in Rhai with full access\nto the SQL AST. No forking required.\n\n**Version-aware.** Configure `postgres_version` to suppress checks that don't apply\nto your version (e.g., constant defaults are safe on PG 11+).\n\n**No database connection required.** Works on SQL files directly — no running Postgres\ninstance needed in CI.\n\n## Installation\n\nVia Cargo:\n```sh\ncargo install diesel-guard\n```\n\nVia Homebrew:\n```sh\nbrew install ayarotsky/tap/diesel-guard\n```\n\nVia shell script (macOS/Linux):\n```sh\ncurl --proto '=https' --tlsv1.2 -LsSf https://github.com/ayarotsky/diesel-guard/releases/latest/download/diesel-guard-installer.sh | sh\n```\n\nVia PowerShell (Windows):\n```powershell\npowershell -ExecutionPolicy Bypass -c \"irm https://github.com/ayarotsky/diesel-guard/releases/latest/download/diesel-guard-installer.ps1 | iex\"\n```\n\nVia pre-commit:\n```yaml\nrepos:\n  - repo: https://github.com/ayarotsky/diesel-guard\n    rev: v0.8.0\n    hooks:\n      - id: diesel-guard\n```\n\n## Quick Start\n\n```sh\ndiesel-guard init   # creates diesel-guard.toml\ndiesel-guard check  # checks ./migrations/ by default\n```\n\nWhen it finds an unsafe migration:\n\n```\n❌ Unsafe migration detected in migrations/20240101_add_admin/up.sql\n\n❌ ADD COLUMN with DEFAULT\n\nProblem:\n  Adding column 'admin' with DEFAULT on table 'users' requires a full table\n  rewrite on Postgres \u003c 11, acquiring an ACCESS EXCLUSIVE lock.\n\nSafe alternative:\n  1. Add the column without a default:\n     ALTER TABLE users ADD COLUMN admin BOOLEAN;\n\n  2. Backfill data in batches (outside migration):\n     UPDATE users SET admin = false WHERE admin IS NULL;\n\n  3. Add default for new rows only:\n     ALTER TABLE users ALTER COLUMN admin SET DEFAULT false;\n```\n\n## CI/CD\n\nAdd to your GitHub Actions workflow:\n\n```yaml\n- uses: actions/checkout@v6\n- uses: ayarotsky/diesel-guard-action@v1\n```\n\nPin the diesel-guard binary version for reproducible builds:\n\n```yaml\n- uses: ayarotsky/diesel-guard-action@v1\n  with:\n    version: '0.10.0'\n```\n\n## What It Detects\n\nBuilt-in checks cover locking, rewrites, and schema safety. See the [full list of checks](https://ayarotsky.github.io/diesel-guard/checks/overview.html).\n\n## Escape Hatch\n\nWhen you've reviewed an operation and confirmed it's safe, wrap it in a safety-assured block to suppress the check:\n\n```sql\n-- safety-assured:start\nALTER TABLE users DROP COLUMN legacy_field;\n-- safety-assured:end\n```\n\n## Further Reading\n\n- [Your Diesel Migrations Might Be Ticking Time Bombs](https://dev.to/ayarotsky/your-diesel-migrations-might-be-ticking-time-bombs-30g7)\n- [Postgres Locks Explained](https://postgreslocksexplained.com/)\n- [Zero-downtime Postgres migrations: the hard parts](https://gocardless.com/blog/zero-downtime-postgres-migrations-the-hard-parts/)\n- [Zero-downtime Postgres migrations: a little help](https://gocardless.com/blog/zero-downtime-postgres-migrations-a-little-help/)\n- [Seven tips for dealing with Postgres locks](https://www.citusdata.com/blog/2018/02/22/seven-tips-for-dealing-with-postgres-locks/)\n- [Move fast and migrate things: how we automated migrations in Postgres](https://benchling.engineering/move-fast-and-migrate-things-how-we-automated-migrations-in-postgres-d60aba0fc3d4)\n- [PostgreSQL at scale: database schema changes without downtime](https://medium.com/paypal-tech/postgresql-at-scale-database-schema-changes-without-downtime-20d3749ed680)\n- [PostgreSQL Explicit Locking](https://www.postgresql.org/docs/current/explicit-locking.html)\n- [Adding a Scripting Engine to a Rust CLI with Rhai](https://dev.to/ayarotsky/adding-a-scripting-engine-to-a-rust-cli-with-rhai-56g1)\n\n## Credits\n\nInspired by [strong_migrations](https://github.com/ankane/strong_migrations) by Andrew Kane.\n\n## License\n\n[MIT](LICENSE)\n\n---\n\nIf this looks useful, a star helps more developers find it ⭐\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayarotsky%2Fdiesel-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayarotsky%2Fdiesel-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayarotsky%2Fdiesel-guard/lists"}