diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-10-22 21:16:59 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-10-24 12:02:00 +0200 |
commit | 393ff04ff4a3cfd944e08e62bdda133dc1e5e3da (patch) | |
tree | a8dccfd58a6d88e958f6e329d669beecec56663d /service-person/src | |
parent | c1ab2c58b68b0a012bb935420d42a6c1661536d3 (diff) |
Run migrations on service startup
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'service-person/src')
-rw-r--r-- | service-person/src/main.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/service-person/src/main.rs b/service-person/src/main.rs index 1a47c51..3c5dc74 100644 --- a/service-person/src/main.rs +++ b/service-person/src/main.rs @@ -1,5 +1,7 @@ #[macro_use] extern crate diesel; +#[macro_use] +extern crate diesel_migrations; use std::str::FromStr; @@ -14,6 +16,7 @@ mod model; use model::*; +embed_migrations!("migrations"); type DbPool = Pool<ConnectionManager<PgConnection>>; @@ -52,6 +55,11 @@ async fn main() -> anyhow::Result<()> { let db_connection_pool = establish_connection(); + { + let conn = db_connection_pool.get().expect("Failed to get connection from pool"); + embedded_migrations::run_with_output(&conn, &mut std::io::stdout()); + } // drop `conn` here + HttpServer::new(move || { App::new() .data(db_connection_pool.clone()) |