Skip to content
项目

关于

SQLX migration using Rust insted of SQL

数据与分析

这些数字如何统计

可以做什么

  • Migrations as Rust values with parents, replaces and run_before.
  • Operations as code, SQL strings or embedded SQL files.
  • CLI (apply, revert, redo, list, repair, prune) and RunReport.
  • Locking, failed migration tracking and hooks.

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

SQLX migrator

A Rust library for writing SQLX migrations using Rust instead of SQL.

License Crates Version Docs
License: MIT Crate Docs

Supported databases: PostgreSQL, SQLite and MySQL.

Features

  • Migrations as Rust values with parents, replaces and run_before.
  • Operations as code, SQL strings or embedded SQL files.
  • CLI (apply, revert, redo, list, repair, prune) and RunReport.
  • Locking, failed migration tracking and hooks.
  • Sync from other migration tools.

Installation

Enable postgres, mysql or sqlite (and json for CLI JSON output):

sqlx_migrator = { version = "0.21.0", features = ["postgres"] }

Quick start

use sqlx_migrator::migrator::{Migrator, Plan};
use sqlx_migrator::vec_box;

struct CreateSample;

// an operation is a `(up, down)` pair of SQL strings, or implement `Operation`
// for code
sqlx_migrator::postgres_migration!(
    CreateSample,
    "main",
    "create_sample",
    vec_box![],
    vec_box![(
        "CREATE TABLE sample (id INTEGER PRIMARY KEY, name TEXT)",
        "DROP TABLE sample"
    )]
);

#[tokio::main]
async fn main() {
    let pool = sqlx::PgPool::connect(&std::env::var("DATABASE_URL").unwrap())
        .await
        .unwrap();
    let mut conn = pool.acquire().await.unwrap();

    let mut migrator = Migrator::default();
    migrator.add_migration(Box::new(CreateSample)).unwrap();
    migrator.run(&mut *conn, &Plan::apply_all()).await.unwrap();
}

Documentation

See the crate docs for the guide, locking, CLI, hooks and sync.

探索相关项目

加载中…