#migration #postgresql #sql #async

tokio-postgres-migration

Library to help you run migrations

1 unstable release

0.1.0 Apr 26, 2021

#125 in #postgres

Download history 80/week @ 2024-11-16 113/week @ 2024-11-23 122/week @ 2024-11-30 154/week @ 2024-12-07 249/week @ 2024-12-14 70/week @ 2024-12-21 31/week @ 2024-12-28 157/week @ 2025-01-04 276/week @ 2025-01-11 245/week @ 2025-01-18 135/week @ 2025-01-25 169/week @ 2025-02-01 268/week @ 2025-02-08 212/week @ 2025-02-15 391/week @ 2025-02-22 244/week @ 2025-03-01

1,160 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

~8–17MB
~241K SLoC