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

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