Skip to content

Commit

Permalink
[Hotfix] Config Parsing (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Jan 22, 2024
1 parent 10c2a47 commit a722fa0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kubernetes/config/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
24 changes: 23 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fn manual_override(
db_url: Option<String>,
) -> Result<Table> {
let mut toml_values = toml_string.parse::<Table>()?;
println!("TOML: {toml_values}");
// Manual overrides from env vars.
if let Some(ethrpc) = node_url {
tracing::info!(
Expand All @@ -104,6 +105,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));
Expand Down Expand Up @@ -214,6 +224,7 @@ mod tests {
ethrpc = "old rpc"
[database.postgres]
connection = "old db"
schema = "anything"
"#
.to_string();

Expand All @@ -230,6 +241,7 @@ mod tests {
ethrpc = "new rpc"
[database.postgres]
connection = "new db"
schema = "anything"
"#
.parse::<Table>()
.unwrap()
Expand All @@ -243,6 +255,7 @@ mod tests {
ethrpc = "new rpc"
[database.postgres]
connection = "old db"
schema = "anything"
"#
.parse::<Table>()
.unwrap()
Expand All @@ -256,18 +269,27 @@ mod tests {
ethrpc = "old rpc"
[database.postgres]
connection = "new db"
schema = "anything"
"#
.parse::<Table>()
.unwrap()
);

// 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::<Table>()
.unwrap()
Expand Down

0 comments on commit a722fa0

Please sign in to comment.