This repository has been archived on 2021-12-24. You can view files and clone it, but cannot push or open issues/pull-requests.
hilde/src/main.rs

35 lines
805 B
Rust
Raw Normal View History

2021-06-27 11:36:54 +02:00
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate diesel_migrations;
2021-06-27 15:00:55 +02:00
use rocket::{fairing::AdHoc, Build, Rocket};
use rocket_sync_db_pools::{database, diesel};
2021-06-27 12:15:54 +02:00
embed_migrations!();
#[database("postgres_hilde")]
struct HildeDbConn(diesel::PgConnection);
async fn run_db_migrations(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocket<Build>> {
2021-06-27 15:00:55 +02:00
let conn = HildeDbConn::get_one(&rocket)
.await
.expect("database connection");
2021-06-27 12:15:54 +02:00
conn.run(|c| match embedded_migrations::run(c) {
Ok(()) => Ok(rocket),
Err(_) => Err(rocket),
2021-06-27 15:00:55 +02:00
})
.await
2021-06-27 12:15:54 +02:00
}
2021-06-27 11:36:54 +02:00
#[launch]
fn rocket() -> _ {
rocket::build()
2021-06-27 12:15:54 +02:00
.attach(HildeDbConn::fairing())
2021-06-27 15:00:55 +02:00
.attach(AdHoc::try_on_ignite(
"Run database migrations",
run_db_migrations,
))
2021-06-16 12:53:32 +02:00
}