feat(main): now database is connected at the start of the app

This commit is contained in:
Raphael 2026-02-12 23:20:33 +01:00
parent 6c858abb0a
commit d746e95b9e
No known key found for this signature in database

View file

@ -3,20 +3,43 @@ mod events;
use events::Bot;
use serenity::all::*;
use sqlx::postgres::PgPoolOptions;
use sqlx::{
Pool, Postgres, migrate
};
use std::env;
#[tokio::main]
async fn main() {
println!("\n");
dotenvy::dotenv().ok();
let token: String =
env::var("DISCORD_TOKEN").expect("❌ | DISCORD_TOKEN missing (check the env file)");
let database_url: String =
env::var("DATABASE_URL").expect("❌ | DATABASE_URL missing (check the env file)");
let db: Pool<Postgres> = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
.expect("❌ | Failed to connect to PostgreSQL");
println!("✅ | Connected to PostgreSQL");
migrate!("./migrations")
.run(&db)
.await
.expect("❌ | Failed to run migrations");
println!("✅ | Migrations applied\n");
let intents: GatewayIntents = GatewayIntents::default();
let bot: Bot = Bot {
commands: commands::import(),
events: events::import(),
database: db,
};
let mut client: Client = Client::builder(&token, intents)