feat: add ssh for database access

This commit is contained in:
Sandro Eiler 2024-02-07 21:59:28 +01:00
parent 1d5b9699b9
commit 13162f6470
5 changed files with 29 additions and 26 deletions

View file

@ -1,7 +1,6 @@
use learn_axum::configuration::{get_configuration, DatabaseSettings};
use learn_axum::telemetry::{get_subscriber, init_subscriber};
use once_cell::sync::Lazy;
use secrecy::ExposeSecret;
use sqlx::{Connection, Executor, PgConnection, PgPool};
use tokio::net::TcpListener;
use uuid::Uuid;
@ -129,17 +128,16 @@ async fn spawn_app() -> TestApp {
pub async fn configure_database(config: &DatabaseSettings) -> PgPool {
// Create database
let mut connection =
PgConnection::connect(&config.connection_string_without_db().expose_secret())
.await
.expect("Failed to connect to Postgres");
let mut connection = PgConnection::connect_with(&config.without_db())
.await
.expect("Failed to connect to Postgres");
connection
.execute(format!(r#"CREATE DATABASE "{}";"#, config.name).as_str())
.await
.expect("Failed to create database.");
// Migrate database
let connection_pool = PgPool::connect(&config.connection_string().expose_secret())
let connection_pool = PgPool::connect_with(config.with_db())
.await
.expect("Failed to connect to Postgres.");
sqlx::migrate!("./migrations")