24 unstable releases (6 breaking)

✓ Uses Rust 2018 edition

0.6.2 Jun 13, 2019
0.5.8 May 28, 2019
0.5.1 Mar 21, 2019
0.4.1 Dec 16, 2018
0.2.0 Mar 4, 2018

#13 in Database interfaces

Download history 309/week @ 2019-05-02 2783/week @ 2019-05-09 1719/week @ 2019-05-16 2225/week @ 2019-05-23 4115/week @ 2019-05-30 2746/week @ 2019-06-06 3223/week @ 2019-06-13 900/week @ 2019-06-20 1582/week @ 2019-06-27 1060/week @ 2019-07-04 890/week @ 2019-07-11 1502/week @ 2019-07-18 1635/week @ 2019-07-25 2215/week @ 2019-08-01 3113/week @ 2019-08-08

4,864 downloads per month
Used in 1 crate

MIT/X11 OR Apache-2.0

1MB
2K SLoC

A powerful database schema builder, that let's you write your SQL migrations in Rust!

barrel offers callback-style builder functions for SQL migrations and is designed to be flexible, portable and fun to use. It provides you with a common interface over SQL, with additional database-specific builders.

This way you can focus on your Rust code, without having to worry about SQL.

Example

The following example will help you get started

use barrel::{types, Migration, Pg};

fn main() {
    let mut m = 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>());
}

Using Diesel

Since diesel 1.2.0 it's possible to now use barrel for migrations with diesel. A guide with some more information on how to get started can be found here

Migration guide

If you've been using barrel to write migrations for diesel before the 0.5.0 release, some migration of your migrations will be required. Since 0.5.0 the way types are constructed changed. Instead of constructing a type with Types::VarChar(255) (an enum variant), the types are now provided by a module called types and builder functions. The same type would now be types::varchar(255) (a function call), which then returns a Type enum.

You can also directly created your own Type builders this way. Check the docs for details!

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.

Conduct

In the interest of fostering an open and welcoming environment, the barrel project pledges to making participation a harassment-free experience for everyone. See Code of Conduct for details. In case of violations, e-mail kookie@spacekookie.de.

Dependencies