Expand description
Apply migratrom migrations through a sqlx::PgPool.
This is the normal application entry point for PostgreSQL. apply_migrations
acquires one pooled connection and pins it for the complete run, so
BEGIN/COMMIT/ROLLBACK and PostgreSQL advisory locks all use the same
session. Use PostgresAdapter only when an application must call the core
engine directly with an already acquired connection.
§Quick start
use migratrom::operations::{create_index, create_table};
use migratrom::{ApplyOptions, ColumnDef, CreateIndexOptions, Migration, PostgresDialect};
use migratrom_postgres::apply_migrations;
use sqlx::PgPool;
let pool = PgPool::connect("postgres://localhost/my_app").await?;
let dialect = PostgresDialect;
let create_users = Migration::new(
1,
None,
vec![create_table(
"public",
"users",
&[ColumnDef::new("id", "bigint"), ColumnDef::new("email", "text")],
None,
&dialect,
)?],
);
let add_email_index = Migration::new(
2,
Some(1),
vec![create_index(
"public",
"users",
"users_email_idx",
&["email".into()],
&CreateIndexOptions { concurrently: true },
&dialect,
)?],
);
apply_migrations(
&[create_users, add_email_index],
&pool,
&ApplyOptions::default(),
).await?;A concurrent index runs outside the migration transaction, as required by
PostgreSQL. The core migratrom::operations cookbook documents all builders,
including PostgreSQL schemas, extensions, enum types, and materialized views.
Structs§
- Postgres
Adapter - A
Dbover one pinned PostgreSQL connection.
Functions§
- apply_
migrations - Apply migrations against a PostgreSQL pool using
PostgresDialect.