aboutsummaryrefslogtreecommitdiff
path: root/development/libs/barrel/examples/pg_strings.rs
blob: 79715b426f0370a1b4d88aed1b20583755f7ed88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
extern crate barrel;

use barrel::backend::Pg;
use barrel::types;
use barrel::*;

fn main() {
    let mut m = Migration::new();

    // A new table is automatically created with an "id" primary key
    // To disable that call `without_id` on the return of `create_table`
    m.create_table("users", |t: &mut Table| {
        t.add_column("name", types::varchar(255)); // Default name is "Anonymous"
        t.add_column("description", types::text().nullable(true)); // Can be null
        t.add_column("age", types::integer());
        t.add_column("posts", types::foreign("posts", vec!["id", "url"]));
        t.add_column("owns_plushy_sharks", types::boolean());
    });

    println!("{}", m.make::<Pg>());
}