Skip to content

Commit 69a5e04

Browse files
authored
feat: add patroni, enhance database configuration and cluster management (#36)
1 parent 87df9a7 commit 69a5e04

File tree

10 files changed

+1007
-66
lines changed

10 files changed

+1007
-66
lines changed

Cargo.lock

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

crates/api/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ async fn main() -> anyhow::Result<()> {
3232

3333
tracing::info!(
3434
"Database: {}:{}/{}",
35-
config.database.host,
35+
config
36+
.database
37+
.host
38+
.as_deref()
39+
.unwrap_or(if !config.database.primary_app_id.is_empty() {
40+
&config.database.primary_app_id
41+
} else {
42+
"localhost"
43+
}),
3644
config.database.port,
3745
config.database.database
3846
);

crates/api/tests/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,26 @@ Tests automatic conversation tracking:
7474
DATABASE_PASSWORD=your_password
7575
```
7676

77-
3. **Valid Session Token**: The tests use `SESSION_TOKEN` constant - ensure you have a valid session in the database
77+
3. **Test Feature Flag**: Most tests require the `test` feature flag to enable the mock-login endpoint
7878

7979
### Run All Tests
8080

8181
```bash
82+
# Run all tests (including admin tests)
83+
cargo test --features test
84+
8285
# Run all E2E tests (they make real OpenAI API calls)
83-
cargo test --test e2e_api_tests -- --ignored --nocapture
86+
cargo test --test e2e_api_tests --features test -- --ignored --nocapture
87+
88+
# Run admin tests
89+
cargo test --test admin_tests --features test
8490

8591
# Run a specific test
86-
cargo test --test e2e_api_tests test_conversation_workflow -- --ignored --nocapture
92+
cargo test --test e2e_api_tests test_conversation_workflow --features test -- --ignored --nocapture
8793
```
8894

95+
**Important**: The `--features test` flag is required for most tests because it enables the `/v1/auth/mock-login` endpoint used for test authentication without requiring real OAuth providers.
96+
8997
### Test Output
9098

9199
The tests provide detailed output showing:

crates/config/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ use serde::Deserialize;
22

33
#[derive(Debug, Clone, Deserialize)]
44
pub struct DatabaseConfig {
5-
pub host: String,
5+
pub host: Option<String>,
66
pub port: u16,
77
pub database: String,
88
pub username: String,
99
pub password: String,
1010
pub max_connections: u32,
1111
pub tls_enabled: bool,
1212
pub tls_ca_cert_path: Option<String>,
13+
pub primary_app_id: String,
14+
pub refresh_interval: u64,
15+
pub mock: bool,
1316
}
1417

1518
impl Default for DatabaseConfig {
1619
fn default() -> Self {
1720
Self {
18-
host: std::env::var("DATABASE_HOST").unwrap_or_else(|_| "localhost".to_string()),
21+
host: std::env::var("DATABASE_HOST").ok(),
1922
port: std::env::var("DATABASE_PORT")
2023
.ok()
2124
.and_then(|p| p.parse().ok())
@@ -32,6 +35,15 @@ impl Default for DatabaseConfig {
3235
.and_then(|v| v.parse().ok())
3336
.unwrap_or(false),
3437
tls_ca_cert_path: std::env::var("DATABASE_TLS_CA_CERT_PATH").ok(),
38+
primary_app_id: std::env::var("DATABASE_PRIMARY_APP_ID").unwrap_or_default(),
39+
refresh_interval: std::env::var("DATABASE_REFRESH_INTERVAL")
40+
.ok()
41+
.and_then(|v| v.parse().ok())
42+
.unwrap_or(30),
43+
mock: std::env::var("DATABASE_MOCK")
44+
.ok()
45+
.and_then(|v| v.parse().ok())
46+
.unwrap_or(false),
3547
}
3648
}
3749
}

crates/database/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ refinery = { version = "0.8", features = ["tokio-postgres"] }
5151
# For hashing API keys and session tokens
5252
sha2 = "0.10"
5353
rand = "0.9.2"
54+
reqwest = { version = "0.12.24", features = ["json", "rustls-tls"] }
55+
deadpool = "0.12.3"
56+
native-tls = "0.2.14"
57+
postgres-native-tls = "0.5.2"

0 commit comments

Comments
 (0)