-
Notifications
You must be signed in to change notification settings - Fork 7
Add DB_URL support #240
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
Add DB_URL support #240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -40,16 +40,18 @@ pub struct GenerateTypesConfig { | |||||||||||||
| pub struct DbConnectionConfig { | ||||||||||||||
| #[serde(rename = "DB_TYPE")] | ||||||||||||||
| pub db_type: DatabaseType, | ||||||||||||||
| #[serde(rename = "DB_HOST")] | ||||||||||||||
| #[serde(rename = "DB_HOST", default)] | ||||||||||||||
| pub db_host: String, | ||||||||||||||
| #[serde(rename = "DB_PORT")] | ||||||||||||||
| #[serde(rename = "DB_PORT", default)] | ||||||||||||||
| pub db_port: u16, | ||||||||||||||
| #[serde(rename = "DB_USER")] | ||||||||||||||
| #[serde(rename = "DB_USER", default)] | ||||||||||||||
| pub db_user: String, | ||||||||||||||
| #[serde(rename = "DB_PASS")] | ||||||||||||||
| pub db_pass: Option<String>, | ||||||||||||||
| #[serde(rename = "DB_NAME")] | ||||||||||||||
| pub db_name: Option<String>, | ||||||||||||||
| #[serde(rename = "DB_URL")] | ||||||||||||||
| pub db_url: Option<String>, | ||||||||||||||
| #[serde(rename = "PG_SEARCH_PATH")] | ||||||||||||||
| pub pg_search_path: Option<String>, | ||||||||||||||
| #[serde(rename = "POOL_SIZE", default = "default_pool_size")] | ||||||||||||||
|
|
@@ -218,43 +220,73 @@ impl Config { | |||||||||||||
| panic!("") | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| let db_host = &CLI_ARGS | ||||||||||||||
| .db_host | ||||||||||||||
| let db_url = &CLI_ARGS | ||||||||||||||
| .db_url | ||||||||||||||
| .clone() | ||||||||||||||
| .or_else(|| dotenv.db_host.clone()) | ||||||||||||||
| .or_else(|| default_config.map(|x| x.db_host.clone())) | ||||||||||||||
| .expect( | ||||||||||||||
| .or_else(|| dotenv.db_url.clone()) | ||||||||||||||
| .or_else(|| default_config.map(|x| x.db_url.clone()).flatten()); | ||||||||||||||
|
|
||||||||||||||
| let db_host_chain = || { | ||||||||||||||
| CLI_ARGS | ||||||||||||||
| .db_host | ||||||||||||||
| .clone() | ||||||||||||||
| .or_else(|| dotenv.db_host.clone()) | ||||||||||||||
| .or_else(|| default_config.map(|x| x.db_host.clone())) | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| let db_host = match (db_url.is_some(), db_host_chain()) { | ||||||||||||||
| (true, Some(v)) => v, | ||||||||||||||
| (true, None) => String::new(), | ||||||||||||||
| (false, Some(v)) => v, | ||||||||||||||
| (false, None) => panic!( | ||||||||||||||
|
Comment on lines
+237
to
+241
|
||||||||||||||
| r" | ||||||||||||||
| Failed to fetch DB host. | ||||||||||||||
| Please provide it at least through a CLI arg or an environment variable or through | ||||||||||||||
| file based configuration | ||||||||||||||
| ", | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| let db_port = &CLI_ARGS | ||||||||||||||
| .db_port | ||||||||||||||
| .or(dotenv.db_port) | ||||||||||||||
| .or_else(|| default_config.map(|x| x.db_port)) | ||||||||||||||
| .expect( | ||||||||||||||
| Failed to fetch DB host. | ||||||||||||||
| Please provide it at least through a CLI arg or an environment variable or through | ||||||||||||||
| file based configuration, or provide a custom DB_URL | ||||||||||||||
| " | ||||||||||||||
| ), | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| let db_port_chain = || { | ||||||||||||||
| CLI_ARGS | ||||||||||||||
| .db_port | ||||||||||||||
| .or(dotenv.db_port) | ||||||||||||||
| .or_else(|| default_config.map(|x| x.db_port)) | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| let db_port = match (db_url.is_some(), db_port_chain()) { | ||||||||||||||
| (true, Some(v)) => v, | ||||||||||||||
| (true, None) => 0, | ||||||||||||||
|
||||||||||||||
| (false, Some(v)) => v, | ||||||||||||||
|
Comment on lines
+258
to
+260
|
||||||||||||||
| (true, Some(v)) => v, | |
| (true, None) => 0, | |
| (false, Some(v)) => v, | |
| (true, Some(v)) => Some(v), | |
| (true, None) => None, | |
| (false, Some(v)) => Some(v), |
Copilot
AI
Dec 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting db_user to an empty string when db_url is provided but no user chain value exists could cause issues if the DB_URL is malformed or missing. Consider validating that db_url is actually valid before allowing empty fallback values.
Copilot
AI
Nov 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Removing .to_owned() calls here changes the ownership semantics. Since these are now owned values instead of references, this is correct, but the surrounding code at lines 328-329 still uses .to_owned() creating inconsistency. Consider applying the same pattern to db_pass and db_name for consistency.
Uh oh!
There was an error while loading. Please reload this page.