summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-10-22 21:16:59 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-10-24 12:02:00 +0200
commit393ff04ff4a3cfd944e08e62bdda133dc1e5e3da (patch)
treea8dccfd58a6d88e958f6e329d669beecec56663d
parentc1ab2c58b68b0a012bb935420d42a6c1661536d3 (diff)
Run migrations on service startup
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--service-person/Cargo.toml1
-rw-r--r--service-person/src/main.rs8
2 files changed, 9 insertions, 0 deletions
diff --git a/service-person/Cargo.toml b/service-person/Cargo.toml
index 7f447a2..530e944 100644
--- a/service-person/Cargo.toml
+++ b/service-person/Cargo.toml
@@ -10,3 +10,4 @@ actix-web = "3.3"
anyhow = "1"
serde = "1"
diesel = { version = "1.4.4", features = ["postgres", "r2d2"] }
+diesel_migrations = "1.4"
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())