#postgresql #sql #migration #async

tokio-postgres-migration

Library to help you run migrations

1 unstable release

0.1.0 Apr 26, 2021

#181 in #migration

Download history 112/week @ 2024-08-29 151/week @ 2024-09-05 182/week @ 2024-09-12 235/week @ 2024-09-19 161/week @ 2024-09-26 124/week @ 2024-10-03 71/week @ 2024-10-10 76/week @ 2024-10-17 88/week @ 2024-10-24 136/week @ 2024-10-31 89/week @ 2024-11-07 93/week @ 2024-11-14 99/week @ 2024-11-21 118/week @ 2024-11-28 134/week @ 2024-12-05 149/week @ 2024-12-12

504 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–16MB
~223K SLoC