~cassaundra/nonbin

9539ea000c8c4be01378627b0ed0692fbc07b0ab — cassaundra 1 year, 6 months ago 70428bf
database: apply migrations on connect
1 files changed, 4 insertions(+), 4 deletions(-)

M src/db.rs
M src/db.rs => src/db.rs +4 -4
@@ 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<Self> {
        Ok(Self {
            pool: AnyPool::connect(url).await?,
        })
        let pool = AnyPool::connect(url).await?;
        sqlx::migrate!().run(&pool).await?;
        Ok(Self { pool })
    }

    /// Get all pastes.