From 9539ea000c8c4be01378627b0ed0692fbc07b0ab Mon Sep 17 00:00:00 2001 From: cassaundra Date: Mon, 15 May 2023 16:42:48 -0700 Subject: [PATCH] database: apply migrations on connect --- src/db.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/db.rs b/src/db.rs index 655e984..1eee9a8 100644 --- a/src/db.rs +++ b/src/db.rs @@ -8,11 +8,11 @@ pub struct Database { } impl Database { - /// Connect to a database by URL. + /// Connect to a database by URL and apply pending migrations. pub async fn connect(url: &str) -> anyhow::Result { - Ok(Self { - pool: AnyPool::connect(url).await?, - }) + let pool = AnyPool::connect(url).await?; + sqlx::migrate!().run(&pool).await?; + Ok(Self { pool }) } /// Get all pastes. -- 2.45.2