Skip to content

Commit

Permalink
feat: run db migrations on main.rs (#3)
Browse files Browse the repository at this point in the history
* Docker compose

* MIgrations

* Re enable trello bot
  • Loading branch information
mhkafadar committed Jan 21, 2024
1 parent fa33bf8 commit 3bc0b4d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
use crate::bots::gitlab_bot::run_gitlab_bot;
use crate::bots::trello_bot::run_trello_bot;
use crate::http_server::run_http_server;

use dotenv::dotenv;
use tokio::task;
use std::env;

pub mod bots;
pub mod http_server;
pub mod webhooks;


use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use std::error::Error;
use diesel::prelude::*;
use diesel::PgConnection;
use diesel::r2d2::{ConnectionManager, Pool, PoolError, PooledConnection};

pub type PgPool = Pool<ConnectionManager<PgConnection>>;
pub type PgPooledConnection = PooledConnection<ConnectionManager<PgConnection>>;

pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations/");

#[tokio::main]
async fn main() {
dotenv().ok();
pretty_env_logger::init();

let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
// Make sure the database is up to date (create if it doesn't exist, or run the migrations)
let manager = ConnectionManager::<PgConnection>::new(database_url);
let pool = diesel::r2d2::Pool::new(manager).unwrap();
let mut connection = pool.get().unwrap();
connection.run_pending_migrations(MIGRATIONS);

task::spawn(run_gitlab_bot());
task::spawn(run_trello_bot());
run_http_server().await.expect("Http server error");
Expand Down

0 comments on commit 3bc0b4d

Please sign in to comment.