Skip to content

Commit

Permalink
chore: common db settings
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Dec 19, 2023
1 parent fccad36 commit b171911
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 18 deletions.
68 changes: 65 additions & 3 deletions user-ops-indexer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions user-ops-indexer/user-ops-indexer-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ amplify = { version = "3.13.0", features = ["derive"] }
anyhow = "1.0"
async-trait = "0.1"
blockscout-display-bytes = "1.0"
blockscout-service-launcher = { version = "0.9.0", features = ["database-0_12"] }
blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs", rev = "22ba428", features = ["database-0_12"] }
config = "0.13"
ethers = "2.0.0"
sea-orm = "0.12.2"
Expand All @@ -29,7 +29,6 @@ tracing = "0.1"
uuid = { version = "1.6.1", features = ["v4"] }

[dev-dependencies]
blockscout-service-launcher = { version = "*", features = ["test-server", "test-database"] }
bytes = "1.5.0"
hex = "0.4.3"
mockall = "0.11"
Expand Down
5 changes: 3 additions & 2 deletions user-ops-indexer/user-ops-indexer-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ async fn main() -> Result<(), anyhow::Error> {
&settings.jaeger,
)?;

let mut connect_options = sea_orm::ConnectOptions::new(&settings.database.url);
let database_url = settings.database.connect.clone().url();
let mut connect_options = sea_orm::ConnectOptions::new(&database_url);
connect_options.sqlx_logging_level(tracing::log::LevelFilter::Debug);
let db_connection = database::initialize_postgres::<Migrator>(
connect_options,
Expand All @@ -26,7 +27,7 @@ async fn main() -> Result<(), anyhow::Error> {
tokio::spawn(run_indexer(settings.clone(), db_connection));

let db_connection =
database::initialize_postgres::<Migrator>(&settings.database.url, false, false).await?;
database::initialize_postgres::<Migrator>(&database_url, false, false).await?;

run_server(settings, db_connection).await
}
13 changes: 2 additions & 11 deletions user-ops-indexer/user-ops-indexer-server/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use blockscout_service_launcher::{
database::{DatabaseConnectSettings, DatabaseSettings},
launcher::{ConfigSettings, MetricsSettings, ServerSettings},
tracing::{JaegerSettings, TracingSettings},
};
Expand Down Expand Up @@ -27,16 +28,6 @@ impl ConfigSettings for Settings {
const SERVICE_NAME: &'static str = "USER_OPS_INDEXER";
}

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct DatabaseSettings {
pub url: String,
#[serde(default)]
pub create_database: bool,
#[serde(default)]
pub run_migrations: bool,
}

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct ApiSettings {
Expand Down Expand Up @@ -125,7 +116,7 @@ impl Settings {
tracing: Default::default(),
jaeger: Default::default(),
database: DatabaseSettings {
url: database_url,
connect: DatabaseConnectSettings::Url(database_url),
create_database: false,
run_migrations: false,
},
Expand Down

0 comments on commit b171911

Please sign in to comment.