1
0
Fork
You've already forked barrel
0
Flexible toolkit for writing SQL schema migrations in Rust
  • Rust 100%
2025年10月02日 06:24:44 +02:00
.github/workflows Create Rust testing action ( #2 ) 2024年12月29日 23:19:49 +00:00
.idea Move test module out of source 2024年12月29日 23:01:09 +00:00
assets Fixing a minor issue in the logo 2019年01月24日 15:15:35 +01:00
docs Fixing blog publish date 2019年03月21日 21:36:22 +01:00
examples Get rid of the tabs, switch to 2024 edition, bump version to 0.10.0 2025年10月02日 06:05:45 +02:00
guides Make it more clear to setup diesel_cli 2021年01月28日 18:17:14 +01:00
src Get rid of the tabs, switch to 2024 edition, bump version to 0.10.0 2025年10月02日 06:05:45 +02:00
tests Get rid of the tabs, switch to 2024 edition, bump version to 0.10.0 2025年10月02日 06:05:45 +02:00
.gitignore "Adding initial file set" 2018年01月11日 18:40:51 +01:00
Cargo.toml Get rid of the tabs, switch to 2024 edition, bump version to 0.10.0 2025年10月02日 06:05:45 +02:00
code_of_conduct.md Adding some more documentation to everything 2018年02月11日 16:42:11 +01:00
FUNDING.yml Add FUNDING.yml 2021年01月28日 17:37:19 +01:00
LICENSE Finally adding a LICENSE file 2018年02月11日 16:33:56 +01:00
README.md Update README 2025年10月02日 06:24:44 +02:00
rustfmt.toml Get rid of the tabs, switch to 2024 edition, bump version to 0.10.0 2025年10月02日 06:05:45 +02:00

Barrel is a flexible toolkit for writing SQL schema migrations as Rust code.

Migrations consist of individual changes to tables, columns, indices, foreign keys, and constraints. It provides composable type builders for all of these changes. Finally a specific backend type (which must be provided as a feature) handle SQL code generation.

Barrel aims to cover all existing SQL features and throws errors (currently panics) when a specific feature doesn't exist for a given database implementation.

Get started

Simply add barrel to your project:

barrel = { version = "0.7", features = [ "..." ] }

Possible feature flags are: sqlite3, mysql, mssql, and pg. You can then get started on writing your first SQL migration in Rust:

usebarrel::{types,Migration};usebarrel::backend::Pg;fn main(){letmutm=Migration::new();m.create_table("users",|t|{t.add_column("name",types::varchar(255));t.add_column("age",types::integer());t.add_column("owns_plushy_sharks",types::boolean());});println!("{}",m.make::<Pg>());}

Note: some generator backends have gotten more attention than others. While I have opted to merge any backend that was offered as a PR, personally I have only ever used Barrel with the sqlite3 backend, which is thus the most well tested. Your mileage may vary!

Upgrade guide & maintenance notice

This crate has been quasi unmaintained from 2021 to 2025 (I wonder what happened 🤔) with multiple versions fragmenting across personal forks. However due to my day job I have been able to pick up development again. A genuine and massive THANK YOU to everyone who has contributed small fixes over the years of my (削除) burnout (削除ここまで) inactivity! 💚💚💚

The version bump from the last "stable" release 0.7.0 to 0.10.0 is meant to indicate a gap in development and represents the chance to fix some long-standing issues both on the API side and the generator internals.

I will keep this README updated with changes that accumulate which may break your migrations, and where possible a migration (hehe) tool will be provided.

License

barrel is free software: you can redistribute it and/or modify it under the terms of the MIT Public License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MIT Public License for more details.