Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 7m33s
23 lines
576 B
Rust
23 lines
576 B
Rust
use std::process::exit;
|
|
|
|
use sqlx::{Pool, Postgres, postgres::PgPoolOptions};
|
|
|
|
pub async fn init(db_url: &str) -> Pool<Postgres> {
|
|
let db = match PgPoolOptions::new().connect(db_url).await {
|
|
Ok(p) => p,
|
|
Err(_) => {
|
|
tracing::error!("Failed to connect to the database");
|
|
exit(1);
|
|
}
|
|
};
|
|
match sqlx::migrate!().run(&db).await {
|
|
Ok(_) => tracing::info!("Migration completed succesfully"),
|
|
Err(_) => {
|
|
tracing::error!("Failed to apply migrations");
|
|
exit(1)
|
|
}
|
|
}
|
|
|
|
db
|
|
}
|