Skip to content

Commit

Permalink
Add migrations to sqlx
Browse files Browse the repository at this point in the history
  • Loading branch information
AltF02 committed Jul 19, 2021
1 parent 7edbeb0 commit 4987ec3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ features = ["macros", "time"]
[dependencies.sqlx]
version = "0.5"
default-features = false
features = ["runtime-tokio-rustls", "macros", "postgres", "uuid", "offline", "chrono"]
features = ["runtime-tokio-rustls", "macros", "postgres", "uuid", "offline", "chrono", "migrate"]

[dependencies.reqwest]
version = "0.11"
Expand Down
9 changes: 6 additions & 3 deletions src/bot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::services::{config::Config, database};
use crate::services::{config::Config, database::Db};

use events::Handler;
use log::warn;
Expand Down Expand Up @@ -65,12 +65,15 @@ pub async fn start(config: Config) {
.await
.expect("Failed to create a new client");

let db = database::Db::new(&config.db_uri).await.unwrap();
let db = Db::new(&config.db_uri)
.await
.expect("Failed to initialize database");
db.run_migrations().await.expect("Failed to run migrations");

{
let mut data = client.data.write().await;
data.insert::<Config>(Arc::new(config));
data.insert::<database::Db>(Arc::new(db));
data.insert::<Db>(Arc::new(db));
}

if let Err(e) = client.start_autosharded().await {
Expand Down

0 comments on commit 4987ec3

Please sign in to comment.