tokio-postgres-migration

Crates.iotokio-postgres-migration
lib.rstokio-postgres-migration
version0.1.0
sourcesrc
created_at2021-04-26 11:54:01.461676
updated_at2021-04-26 11:54:01.461676
descriptionLibrary to help you run migrations
homepage
repositoryhttps://github.com/jdrouet/tokio-postgres-migration
max_upload_size
id389662
size7,960
Jérémie Drouet (jdrouet)

documentation

README

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?;
Commit count: 1

cargo fmt