Crates.io | reshape_helper |
lib.rs | reshape_helper |
version | 0.1.1 |
source | src |
created_at | 2022-04-19 18:04:45.576819 |
updated_at | 2022-08-03 14:02:52.884603 |
description | Helper library for Reshape |
homepage | https://github.com/fabianlindfors/reshape-helper |
repository | https://github.com/fabianlindfors/reshape-helper |
max_upload_size | |
id | 570536 |
size | 9,465 |
This is a Rust helper library for the automated, zero-downtime schema migration tool Reshape. To achieve zero-downtime migrations, Reshape requires that your application runs a simple query when it opens a connection to the database to select the right schema. This library automates that process and provides a macro to embed the right query directly in your application.
Add reshape_helper
as a dependency to your Cargo.toml
:
[dependencies]
reshape_helper = "0.1.1"
The library exposes a single macro which will find all your Reshape migration files and determine the right schema query to run. The macro will be evaluated at compile time and the query embedded directly in your binary, so you won't need to keep your migration files around at runtime.
The following is an example of how to use the library together with SQLx (but it works with any Postgres client):
use reshape_helper::schema_query
use sqlx::postgres::PgPoolOptions;
#[async_std::main]
async fn main() {
let reshape_schema_query = schema_query!();
let pool = PgPoolOptions::new()
.after_connect(|conn| Box::pin(async move {
conn.execute(reshape_schema_query).await?;
Ok(())
}))
.connect("postgres://postgres@localhost:5432/db").await?;
}
By default, schema_query!
will look for migration files in migrations/
but you can specify your own directories as well:
use reshape_helper::schema_query
fn main() {
let reshape_schema_query = schema_query!(
"src/users/migrations",
"src/todos/migrations",
);
// Execute reshape_schema_query against your database...
}
Released under the MIT license.