Re-added auto migrations
This commit is contained in:
@@ -6,15 +6,22 @@ use actix_web::HttpServer;
|
||||
use actix_web::App;
|
||||
use actix_web::web;
|
||||
use diesel::PgConnection;
|
||||
use diesel::r2d2::{ConnectionManager, Pool};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use request::{login, register, gamenights, gamenight_post, gamenight_get};
|
||||
use diesel::r2d2::ConnectionManager;
|
||||
use diesel::r2d2::Pool;
|
||||
use util::GetConnection;
|
||||
|
||||
pub(crate) type DbPool = Pool<ConnectionManager<PgConnection>>;
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
||||
fn run_migration(conn: &mut PgConnection) {
|
||||
conn.run_pending_migrations(MIGRATIONS).unwrap();
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let url = "postgres://root:root@localhost/gamenight";
|
||||
let url = "postgres://root:root@127.0.0.1/gamenight";
|
||||
let manager = ConnectionManager::<PgConnection>::new(url);
|
||||
// Refer to the `r2d2` documentation for more methods to use
|
||||
// when building a connection pool
|
||||
@@ -23,6 +30,9 @@ async fn main() -> std::io::Result<()> {
|
||||
.build(manager)
|
||||
.expect("Could not build connection pool");
|
||||
|
||||
let mut conn = pool.get_conn();
|
||||
run_migration(&mut conn);
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::Data::new(pool.clone()))
|
||||
|
||||
Reference in New Issue
Block a user