diff --git a/crates/post3-server/src/cli.rs b/crates/post3-server/src/cli.rs index 6fe9c79..9a2713e 100644 --- a/crates/post3-server/src/cli.rs +++ b/crates/post3-server/src/cli.rs @@ -29,10 +29,7 @@ pub async fn execute() -> anyhow::Result<()> { std::env::var("DATABASE_URL").context("DATABASE_URL not set")?; let pool = PgPool::connect(&database_url).await?; - sqlx::migrate!("../post3/migrations/") - .set_locking(false) - .run(&pool) - .await?; + post3::MIGRATOR.run(&pool).await?; tracing::info!("database migrations applied"); diff --git a/crates/post3-server/tests/common/mod.rs b/crates/post3-server/tests/common/mod.rs index 548f66d..ce300a0 100644 --- a/crates/post3-server/tests/common/mod.rs +++ b/crates/post3-server/tests/common/mod.rs @@ -44,11 +44,7 @@ impl TestServer { .unwrap(); // Run migrations - sqlx::migrate!("../post3/migrations/") - .set_locking(false) - .run(&pool) - .await - .unwrap(); + post3::MIGRATOR.run(&pool).await.unwrap(); // Clean slate sqlx::query("DELETE FROM upload_parts").execute(&pool).await.unwrap(); diff --git a/crates/post3/src/lib.rs b/crates/post3/src/lib.rs index 755bdbd..6df89f5 100644 --- a/crates/post3/src/lib.rs +++ b/crates/post3/src/lib.rs @@ -9,3 +9,6 @@ pub use backend::StorageBackend; pub use error::Post3Error; pub use fs::FilesystemBackend; pub use store::{PostgresBackend, Store}; + +/// Embedded database migrations. Run with `MIGRATOR.run(&pool).await`. +pub static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!("./migrations");