refinery

Powerful SQL migration toolkit for Rust, embeddable in your app or run via CLI.

Library
Cargo
v0.9.2
1,697stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
64/100Good
Development Activity60
Maintenance36
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture78
Code Quality74
Innovation60
Learning Curve65

refinery runs versioned database migrations for Rust applications, either embedded directly in your binary via the embed_migrations! macro or driven from the command line through the companion refinery_cli crate. It supports Postgres, MySQL, SQLite, and MSSQL through pluggable driver features, with both synchronous and async runners.

What You Get

  • embed_migrations! macro to bake versioned migrations into your compiled binary
  • Sync and async Runner APIs (run/run_async) across postgres, mysql, rusqlite, and tiberius drivers
  • SQL-file or Rust-function migrations with strict (V) or non-contiguous (U) versioning
  • A separate refinery_cli crate for running migrations from the command line via DATABASE_URL

Common Use Cases

  • Applying schema migrations automatically at application startup for Postgres/MySQL/SQLite/MSSQL
  • Running database migrations from CI/CD pipelines via the refinery CLI against a DATABASE_URL
  • Coordinating schema changes across a team using non-contiguous migration versioning to avoid merge conflicts
  • Baking migrations into a single deployable binary so no separate migration files are needed at runtime

Under The Hood

Architecture - The workspace separates the driver-agnostic engine (refinery_core, with traits/mod.rs and traits/async.rs defining the sync/async Migrate traits that each database driver implements), the embed_migrations!/refinery::config macros (refinery_macros), the public facade crate (refinery) that re-exports both behind feature flags, and a standalone refinery_cli binary crate that wraps the same core engine behind a command-line interface reading a Config/DATABASE_URL. Tech Stack - Rust 2018/2021 across the workspace (MSRV 1.85 pinned at the workspace level), with optional driver dependencies gated per feature (postgres, tokio-postgres, mysql, mysql_async, rusqlite, tiberius), toml/serde for config parsing, and dev-dependencies including barrel for schema-generation examples and tokio/futures for async test coverage. Code Quality - Tests span the core engine and CLI (assert_cmd/predicates used to test CLI behavior end-to-end), with async coverage exercised via tokio across supported drivers; the project has run for 8+ years with sustained community contribution (87 contributors) though the maintainers have explicitly scoped down driver support to keep bandwidth manageable, pushing new drivers to external repos. API Design - The API centers on a small Runner type obtained from migrations::runner() with .run()/.run_async() entry points per driver feature, plus the embed_migrations! macro for compile-time embedding — deliberately narrow, following the Flyway migration philosophy (no auto-generated rollback/undo migrations).

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search