Crate declare_schema

Source
Expand description

Diff SQL and a Postgres server to execute migrations

Example

let pool = sqlx::PgPool::connect(env::var(key)?.as_str()).await?;
let target_schema = include_str!("schema.sql");
declare_schema::migrate_from_string(&target_schema, &pool).await?;

Diff SQL and a Postgres server to generate migration statements

Example

let pool = sqlx::PgPool::connect(env::var(key)?.as_str()).await?;
let target_schema = include_str!("schema.sql");
let steps = declare_schema::generate_migrations_from_string(&target_schema, &pool).await?;
for step in steps {
    println!("{}", step)
}

Modules§

altertable
Diff’ing of ASTs and statement generation
schema
str parsing to generate sqlparser ASTs
source_postgres
Postgres Server reading to generate sqlparser ASTs

Enums§

MigrationError
The common error type for migration errors

Functions§

generate_migrations_from_string
Diff a str with a DB and return SQL changes required to get the DB to match str
migrate_from_string
Diff a str with a DB and apply changes required to get the DB to match str