From 3ca4a042eb511ce65a31a19d534eb196a193cf23 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 22 Jan 2024 15:56:26 +0100 Subject: [PATCH 1/2] fix config parsing --- kubernetes/config/configmap.yaml | 4 ++-- src/config.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kubernetes/config/configmap.yaml b/kubernetes/config/configmap.yaml index 62b15bc..d7eef23 100644 --- a/kubernetes/config/configmap.yaml +++ b/kubernetes/config/configmap.yaml @@ -10,8 +10,8 @@ data: schema = "mainnet" [indexer] - page-size = 200 - poll-interval = 1 + page-size = 25 + poll-interval = 10 ## ERC721: https://eips.ethereum.org/EIPS/eip-721#specification [[event]] diff --git a/src/config.rs b/src/config.rs index b30558f..8557f39 100644 --- a/src/config.rs +++ b/src/config.rs @@ -72,6 +72,7 @@ impl Config { db_url: Option, ) -> Result<(Self, PathBuf)> { let toml = manual_override(fs::read_to_string(path)?, node_url, db_url)?; + println!("TOML {}", toml); let config: Config = toml::from_str(&toml.to_string())?; let root = fs::canonicalize(path)? @@ -88,6 +89,7 @@ fn manual_override( db_url: Option, ) -> Result { let mut toml_values = toml_string.parse::
()?; + println!("TOML: {toml_values}"); // Manual overrides from env vars. if let Some(ethrpc) = node_url { tracing::info!( @@ -104,6 +106,15 @@ fn manual_override( if connection.contains("file:") { db_type.insert("sqlite".to_string(), Value::Table(db_data)) } else { + // In the event that postgres is specified, + // schema is expected to be part of the config. + db_data.insert( + "schema".to_string(), + toml_values["database"]["postgres"] + .get("schema") + .expect("schema required for postgres connection") + .clone(), + ); db_type.insert("postgres".to_string(), Value::Table(db_data)) }; toml_values.insert("database".to_string(), Value::Table(db_type)); From 301753ea298697953efa995bee3f81d4f95f604a Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 22 Jan 2024 16:04:35 +0100 Subject: [PATCH 2/2] fix config parsing test --- src/config.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8557f39..e2e14c7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -72,7 +72,6 @@ impl Config { db_url: Option, ) -> Result<(Self, PathBuf)> { let toml = manual_override(fs::read_to_string(path)?, node_url, db_url)?; - println!("TOML {}", toml); let config: Config = toml::from_str(&toml.to_string())?; let root = fs::canonicalize(path)? @@ -225,6 +224,7 @@ mod tests { ethrpc = "old rpc" [database.postgres] connection = "old db" + schema = "anything" "# .to_string(); @@ -241,6 +241,7 @@ mod tests { ethrpc = "new rpc" [database.postgres] connection = "new db" + schema = "anything" "# .parse::
() .unwrap() @@ -254,6 +255,7 @@ mod tests { ethrpc = "new rpc" [database.postgres] connection = "old db" + schema = "anything" "# .parse::
() .unwrap() @@ -267,6 +269,7 @@ mod tests { ethrpc = "old rpc" [database.postgres] connection = "new db" + schema = "anything" "# .parse::
() .unwrap() @@ -274,11 +277,19 @@ mod tests { // toml without node or db provided assert_eq!( - manual_override("".to_string(), node_url, db_url).unwrap(), + manual_override( + r#"[database.postgres] + schema = "anything""# + .to_string(), + node_url, + db_url + ) + .unwrap(), r#" ethrpc = "new rpc" [database.postgres] connection = "new db" + schema = "anything" "# .parse::
() .unwrap()