Skip to content

Commit 444b643

Browse files
committed
feat: update database configuration to support SSL and add max connections setting
1 parent 61bfe2c commit 444b643

File tree

5 files changed

+145
-6
lines changed

5 files changed

+145
-6
lines changed

apps/backend/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
DATABASE_URL=postgres://user:password@localhost:5432/sourcemaps
1+
DATABASE_URL=postgres://user:password@localhost:5432/sourcemaps?sslmode=require
2+
DATABASE_MAX_CONNECTIONS=3
23
FILE_ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000000
34
APIKEY_ENCRYPTION_KEY=1111111111111111111111111111111111111111111111111111111111111111
45
S3_BUCKET=

apps/backend/Cargo.lock

Lines changed: 135 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rand = "0.9.1"
1414
serde = { version = "1.0.228", features = ["derive"] }
1515
serde_json = "1.0.140"
1616
sourcemap = "9.3.2"
17-
sqlx = { version = "0.8.6", features = ["runtime-tokio", "postgres", "uuid"] }
17+
sqlx = { version = "0.8.6", features = ["runtime-tokio", "tls-native-tls", "postgres", "uuid"] }
1818
thiserror = "2.0.12"
1919
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] }
2020
tower-http = { version = "0.6.6", features = ["cors", "trace"] }

apps/backend/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::net::SocketAddr;
33
#[derive(Clone)]
44
pub struct Config {
55
pub database_url: String,
6+
pub database_max_connections: u32,
67
pub file_encryption_key: String,
78
pub apikey_encryption_key: String,
89
pub s3_bucket: String,
@@ -30,6 +31,10 @@ impl Config {
3031

3132
Ok(Self {
3233
database_url: std::env::var("DATABASE_URL")?,
34+
database_max_connections: std::env::var("DATABASE_MAX_CONNECTIONS")
35+
.unwrap_or_else(|_| "3".into())
36+
.parse()
37+
.expect("DATABASE_MAX_CONNECTIONS must be a valid u32"),
3338
file_encryption_key: std::env::var("FILE_ENCRYPTION_KEY")
3439
.or_else(|_| std::env::var("ENCRYPTION_KEY"))?,
3540
apikey_encryption_key: std::env::var("APIKEY_ENCRYPTION_KEY")

apps/backend/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ async fn build_state(config: &Config) -> AppState {
7171
Crypto::new(&config.apikey_encryption_key).expect("invalid APIKEY_ENCRYPTION_KEY"),
7272
);
7373
let db = PgPoolOptions::new()
74-
.max_connections(10)
74+
.max_connections(config.database_max_connections)
7575
.connect(&config.database_url)
7676
.await
7777
.expect("failed to connect to database");
78+
info!("connected to postgres");
7879
let s3_client = s3_client(config);
7980
let storage = Storage::new(s3_client, config.s3_bucket.clone(), file_crypto.clone());
8081

0 commit comments

Comments
 (0)