Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hotfix] Config Parsing #28

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading