server: Embed migrations

This commit is contained in:
Elias Projahn 2020-11-29 18:58:50 +01:00
parent f960971fdb
commit 6a40921ac4
3 changed files with 12 additions and 0 deletions

View file

@ -9,6 +9,7 @@ actix-web-httpauth = "0.5.0"
anyhow = "1.0.34" anyhow = "1.0.34"
derive_more = "0.99.11" derive_more = "0.99.11"
diesel = { version = "1.4.4", features = ["postgres", "r2d2"] } diesel = { version = "1.4.4", features = ["postgres", "r2d2"] }
diesel_migrations = "1.4.0"
dotenv = "0.15.0" dotenv = "0.15.0"
env_logger = "0.8.1" env_logger = "0.8.1"
jsonwebtoken = "7.2.0" jsonwebtoken = "7.2.0"

View file

@ -22,6 +22,9 @@ pub use works::*;
mod schema; mod schema;
// This makes the SQL migration scripts accessible from the code.
embed_migrations!();
/// A pool of connections to the database. /// A pool of connections to the database.
pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>; pub type DbPool = r2d2::Pool<r2d2::ConnectionManager<PgConnection>>;
@ -35,5 +38,9 @@ pub fn connect() -> Result<DbPool> {
let manager = r2d2::ConnectionManager::<PgConnection>::new(url); let manager = r2d2::ConnectionManager::<PgConnection>::new(url);
let pool = r2d2::Pool::new(manager)?; let pool = r2d2::Pool::new(manager)?;
// Run embedded migrations.
let conn = pool.get()?;
embedded_migrations::run(&conn)?;
Ok(pool) Ok(pool)
} }

View file

@ -2,6 +2,10 @@
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
// Required for embed_migrations macro in database/mod.rs
#[macro_use]
extern crate diesel_migrations;
use actix_web::{App, HttpServer}; use actix_web::{App, HttpServer};
mod database; mod database;