#postgresql #sql #migration #async

tokio-postgres-migration

Library to help you run migrations

1 unstable release

0.1.0 Apr 26, 2021

#174 in #migration

Download history 142/week @ 2024-07-22 157/week @ 2024-07-29 97/week @ 2024-08-05 106/week @ 2024-08-12 114/week @ 2024-08-19 88/week @ 2024-08-26 145/week @ 2024-09-02 152/week @ 2024-09-09 207/week @ 2024-09-16 225/week @ 2024-09-23 160/week @ 2024-09-30 59/week @ 2024-10-07 84/week @ 2024-10-14 86/week @ 2024-10-21 100/week @ 2024-10-28 120/week @ 2024-11-04

392 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
~221K SLoC