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

Bug fix: the configuration directory from the CLI is not taken into account when generating the default database path #591

Merged
merged 12 commits into from
Sep 14, 2024
10 changes: 7 additions & 3 deletions src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ impl AppConfig {
if let Some(config_dir) = &cli.config_dir {
config.configuration_directory.clone_from(config_dir);
}

config.configuration_directory = cli.config_dir.clone().unwrap_or(PathBuf::from("./sqlpage"));
config.database_url = default_database_url(&config.configuration_directory);

config.validate()?;
Ok(config)
}
Expand Down Expand Up @@ -104,7 +108,7 @@ pub fn load_from_env() -> anyhow::Result<AppConfig> {

#[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct AppConfig {
#[serde(default = "default_database_url")]
#[serde(default)]
pub database_url: String,
pub max_database_pool_connections: Option<u32>,
pub database_connection_idle_timeout_seconds: Option<f64>,
Expand Down Expand Up @@ -332,7 +336,7 @@ fn parse_socket_addr(host_str: &str) -> anyhow::Result<SocketAddr> {
.with_context(|| format!("host '{host_str}' does not resolve to an IP"))
}

fn default_database_url() -> String {
fn default_database_url(configuration_directory: &PathBuf) -> String {
let prefix = "sqlite://".to_owned();

if cfg!(test) {
Expand All @@ -341,7 +345,7 @@ fn default_database_url() -> String {

#[cfg(not(feature = "lambda-web"))]
{
let config_dir = cannonicalize_if_possible(&configuration_directory());
let config_dir = cannonicalize_if_possible(configuration_directory.as_path());
let old_default_db_path = PathBuf::from(DEFAULT_DATABASE_FILE);
let default_db_path = config_dir.join(DEFAULT_DATABASE_FILE);
if let Ok(true) = old_default_db_path.try_exists() {
Expand Down
Loading