server: Embed migrations

This commit is contained in:
Elias Projahn 2020-11-29 18:58:50 +01:00
parent f960971fdb
commit 6a40921ac4
3 changed files with 12 additions and 0 deletions

View file

@ -22,6 +22,9 @@ pub use works::*;
mod schema;
// This makes the SQL migration scripts accessible from the code.
embed_migrations!();
/// A pool of connections to the database.
pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>;
@ -35,5 +38,9 @@ pub fn connect() -> Result<DbPool> {
let manager = r2d2::ConnectionManager::<PgConnection>::new(url);
let pool = r2d2::Pool::new(manager)?;
// Run embedded migrations.
let conn = pool.get()?;
embedded_migrations::run(&conn)?;
Ok(pool)
}