#迁移 #postgresql #sql #异步

tokio-postgres-migration

帮助您运行迁移的库

1个不稳定版本

0.1.0 2021年4月26日

#172#迁移

Download history 140/week @ 2024-03-14 210/week @ 2024-03-21 166/week @ 2024-03-28 114/week @ 2024-04-04 108/week @ 2024-04-11 133/week @ 2024-04-18 127/week @ 2024-04-25 112/week @ 2024-05-02 129/week @ 2024-05-09 113/week @ 2024-05-16 149/week @ 2024-05-23 149/week @ 2024-05-30 150/week @ 2024-06-06 132/week @ 2024-06-13 126/week @ 2024-06-20 90/week @ 2024-06-27

每月517 次下载
2 crates 中使用

MIT/Apache

8KB
140

Tokio Postgres迁移

运行postgres迁移的简单库

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?;

依赖关系

~7–16MB
~231K SLoC