aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main.rs15
-rw-r--r--server/src/schema.rs6
2 files changed, 13 insertions, 8 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
}
diff --git a/server/src/schema.rs b/server/src/schema.rs
index 5d823c0..3fa7ce9 100644
--- a/server/src/schema.rs
+++ b/server/src/schema.rs
@@ -1,6 +1,6 @@
table! {
links (hash) {
- hash -> Text,
- url -> Text,
+ hash -> Bpchar,
+ url -> Varchar,
}
-} \ No newline at end of file
+}