#migration #postgresql #sql #async

tokio-postgres-migration

Library to help you run migrations

1 unstable release

0.1.0 Apr 26, 2021

#76 in #postgres

Download history 66/week @ 2024-02-05 64/week @ 2024-02-12 105/week @ 2024-02-19 117/week @ 2024-02-26 109/week @ 2024-03-04 142/week @ 2024-03-11 210/week @ 2024-03-18 156/week @ 2024-03-25 170/week @ 2024-04-01 94/week @ 2024-04-08 131/week @ 2024-04-15 122/week @ 2024-04-22 106/week @ 2024-04-29 126/week @ 2024-05-06 120/week @ 2024-05-13 116/week @ 2024-05-20

486 downloads per month
Used in 2 crates

MIT/Apache

8KB
140 lines

Tokio Postgres migration

Simple library to run postgres migrations

use tokio_postgres_migration::Migration;

const SCRIPTS_UP: [(&str, &str); 2] = [
    (
        "0001-create-table-users",
        include_str!("../assets/0001-create-table-users-up.sql"),
    ),
    (
        "0002-create-table-pets",
        include_str!("../assets/0002-create-table-pets-up.sql"),
    ),
];

const SCRIPTS_DOWN: [(&str, &str); 2] = [
    (
        "0002-create-table-pets",
        include_str!("../assets/0002-create-table-pets-down.sql"),
    ),
    (
        "0001-create-table-users",
        include_str!("../assets/0001-create-table-users-down.sql"),
    ),
];

let mut client = build_postgres_client().await?;
let migration = Migration::new("table_to_keep_migrations".to_string());
// execute non existing migrations
migration.up(&mut client, &SCRIPTS_UP).await?;
// execute existing migrations
migration.down(&mut client, &SCRIPTS_DOWN).await?;

Dependencies

~7–17MB
~234K SLoC