1个不稳定版本
0.1.0 | 2021年4月26日 |
---|
#172 在 #迁移
每月517 次下载
在 2 crates 中使用
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