diff --git a/config/development.example.toml b/config/development.example.toml index 54034bf..c7056fd 100644 --- a/config/development.example.toml +++ b/config/development.example.toml @@ -13,7 +13,7 @@ url = "your sentry DSN here" [database] pg_host = "localhost" # If running as a docker container, change this to musicbrainz-docker-db-1 -pg_port = "5432" +pg_port = 5432 pg_user = "musicbrainz" pg_password = "musicbrainz" pg_database = "musicbrainz_db" diff --git a/config/production.example.toml b/config/production.example.toml index e7df7d1..68aacaf 100644 --- a/config/production.example.toml +++ b/config/production.example.toml @@ -9,7 +9,7 @@ url = "enter your project url" [database] pg_host = "" -pg_port = "" +pg_port = 5432 pg_user = "" pg_password = "" pg_database = "" diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index ae527d5..c2ee101 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -40,7 +40,7 @@ pub struct Sentry { #[derive(Debug, Deserialize)] pub struct Database { pub pg_host: String, - pub pg_port: String, + pub pg_port: u16, pub pg_user: String, pub pg_password: String, pub pg_database: String, diff --git a/src/main.rs b/src/main.rs index ad6b4b9..1e22161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use crate::configuration::Settings; -use sqlx::postgres::PgPoolOptions; +use sqlx::postgres::{PgConnectOptions, PgPoolOptions}; mod app; mod archival; @@ -38,13 +38,18 @@ fn main() { let password = settings.database.pg_password; let port = settings.database.pg_port; let db = settings.database.pg_database; - let db_url = format!( - "postgres://{}:{}@{}:{}/{}", - user, password, hostname, port, db - ); + + let connect_options = PgConnectOptions::new() + .host(&hostname) + .port(port) + .username(&user) + .password(&password) + .database(&db) + .statement_cache_capacity(0); + let pool = PgPoolOptions::new() .max_connections(5) - .connect(&db_url) + .connect_with(connect_options) .await .expect("Failed to connect to the database");