Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions common/src/indexer_service/http/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,42 @@ use std::net::SocketAddr;

use serde::{Deserialize, Serialize};
use thegraph_core::{Address, DeploymentId};
use tracing::warn;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DatabaseConfig {
pub postgres_url: String,
}
impl DatabaseConfig {
pub fn format_db_config(
ps_url: Option<String>,
ps_host: Option<String>,
ps_pwd: Option<String>,
ps_port: Option<String>,
ps_user: Option<String>,
ps_db: Option<String>,
) -> Self {
let db_config = (ps_url, ps_host, ps_pwd, ps_port, ps_user, ps_db);
match db_config {
(Some(url), ..) if !url.is_empty() => DatabaseConfig { postgres_url: url },
(None, Some(host), Some(pwd), Some(port), Some(user), Some(dbname)) => {
let postgres_url =
format!("postgres://{}:{}@{}:{}/{}", user, pwd, host, port, dbname);
DatabaseConfig { postgres_url }
}
_ => {
warn!(
"Some configuration values are missing for database values, please make sure you either \
pass `postgres_url` or pass all the variables to connect to the database
");
// This will eventually fail to connect
DatabaseConfig {
postgres_url: String::new(),
}
}
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SubgraphConfig {
Expand Down
7 changes: 7 additions & 0 deletions config/maximal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ port = 7300
# that is used by the `indexer-agent`. It is expected that `indexer-agent` will create
# the necessary tables.
postgres_url = "postgres://postgres@postgres:5432/postgres"
# You can also use the following fields to specify the connection details separately.
# either use `postgres_url` or the following fields.
postgres_host = "postgres-host"
postgres_port = 5432
postgres_user = "user"
postgres_password = "pwd"
postgress_db = "postgres"

[graph_node]
# URL to your graph-node's query endpoint
Expand Down
7 changes: 7 additions & 0 deletions config/minimal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ operator_mnemonic = "celery smart tip orange scare van steel radio dragon joy al
# that is used by the `indexer-agent`. It is expected that `indexer-agent` will create
# the necessary tables.
postgres_url = "postgres://postgres@postgres:5432/postgres"
# You can also use the following fields to specify the connection details separately.
# either use `postgres_url` or the following fields.
postgres_host = "postgres-host"
postgres_port = 5432
postgres_user = "user"
postgres_password = "pwd"
postgress_db = "postgres"

[graph_node]
# URL to your graph-node's query endpoint
Expand Down
5 changes: 5 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ pub struct IndexerConfig {
#[cfg_attr(test, derive(PartialEq))]
pub struct DatabaseConfig {
pub postgres_url: Url,
pub postgres_host: String,
pub postgres_port: i32,
pub postgres_user: String,
pub postgres_password: String,
pub postgress_db: String,
}

#[derive(Debug, Deserialize)]
Expand Down
11 changes: 8 additions & 3 deletions service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ impl From<MainConfig> for Config {
url_prefix: value.service.url_prefix,
free_query_auth_token: value.service.free_query_auth_token,
},
database: DatabaseConfig {
postgres_url: value.database.postgres_url.into(),
},
database: DatabaseConfig::format_db_config(
Some(value.database.postgres_url.into()),
Some(value.database.postgres_host),
Some(value.database.postgres_password),
Some(value.database.postgres_port.to_string()),
Some(value.database.postgres_user),
Some(value.database.postgress_db),
),
graph_node: Some(GraphNodeConfig {
status_url: value.graph_node.status_url.into(),
query_base_url: value.graph_node.query_url.into(),
Expand Down
Loading