about summary refs log tree commit diff
path: root/server/src/main.rs
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-01-13 22:37:31 +0100
committerMelonai <einebeere@gmail.com>2021-01-13 22:37:31 +0100
commit5b6ed8cfb245f7f9991f5fc192b8c9215f0ecdc1 (patch)
treec4b9ef58c708900d2a88fa5e8790629d415e2b75 /server/src/main.rs
parent6e8a1117ddef390453d6b695c301d7f4d219f947 (diff)
downloadshorest-5b6ed8cfb245f7f9991f5fc192b8c9215f0ecdc1.tar.zst
shorest-5b6ed8cfb245f7f9991f5fc192b8c9215f0ecdc1.zip
Created diesel migrations
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 92df222..515fc8f 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -1,5 +1,6 @@
 extern crate openssl;
 #[macro_use] extern crate diesel;
+#[macro_use] extern crate diesel_migrations;
 #[macro_use] extern crate serde_derive;
 
 mod schema;
@@ -92,16 +93,20 @@ async fn redirect(info: Path<String>, state: Data<PoolState>) -> HttpResponse {
     }
 }
 
+embed_migrations!("migrations");
+
+fn run_migrations(pool: &PoolState) {
+    let migration_connection = &pool.get().expect("Could not connect to database to run migrations");
+    embedded_migrations::run_with_output(migration_connection, &mut std::io::stdout());
+}
+
 #[actix_rt::main]
 async fn main() -> std::io::Result<()> {
     std::env::set_var("RUST_LOG", "actix_web=info");
     env_logger::init();
 
     let pool = establish_connection();
-    let port = std::env::var("PORT")
-        .unwrap()
-        .parse()
-        .expect("PORT must be a number.");
+    run_migrations(&pool);
 
     HttpServer::new(move || {
         App::new()
@@ -120,7 +125,7 @@ async fn main() -> std::io::Result<()> {
                 Files::new("/client/", "./client/")
             )
     })
-        .bind(("0.0.0.0", port))?
+        .bind(("0.0.0.0", 80))?
         .run()
         .await
 }