DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

84a7064991647018aeb67b6a9e92ec662ab4ebad — Jonni Liljamo 1 year, 10 months ago be173cd
feat(api): embed migrations
1 files changed, 11 insertions(+), 0 deletions(-)

M api/src/main.rs
M api/src/main.rs => api/src/main.rs +11 -0
@@ 13,14 13,21 @@ use diesel::{
    r2d2::{self, ConnectionManager},
    PgConnection,
};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};

type PgPool = r2d2::Pool<ConnectionManager<PgConnection>>;

const MIGRATIONS: EmbeddedMigrations = embed_migrations!();

#[get("/ping")]
async fn ping() -> impl Responder {
    HttpResponse::Ok().body("pong")
}

fn run_migrations(conn: &mut PgConnection) {
    conn.run_pending_migrations(MIGRATIONS).unwrap();
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    pretty_env_logger::init();


@@ 35,6 42,10 @@ async fn main() -> std::io::Result<()> {
        .build(manager)
        .expect("failed to create pool");

    // run migrations
    log::info!("running migrations");
    run_migrations(&mut pg_pool.get().unwrap());

    HttpServer::new(move || {
        App::new()
            .app_data(web::Data::new(pg_pool.clone()))