]> Untitled Git - lemmy.git/commitdiff
Make some of the database config values optional (fixes #1550)
authorFelix Ableitner <me@nutomic.com>
Tue, 6 Apr 2021 12:57:37 +0000 (14:57 +0200)
committerFelix Ableitner <me@nutomic.com>
Tue, 6 Apr 2021 12:57:37 +0000 (14:57 +0200)
crates/utils/src/settings/defaults.rs
crates/utils/src/settings/mod.rs
crates/utils/src/settings/structs.rs
docker/dev/docker_update_volume_mount.sh
docker/dev/volume_mount.dockerfile
src/main.rs

index 56d24c7fb273393b5fd380268df4ff89d30f37a7..1ca15d248ed0583d128ebbac3369d7e2fb1b3e8d 100644 (file)
@@ -21,15 +21,20 @@ impl Default for Settings {
   }
 }
 
+pub(in crate::settings) static DEFAULT_DATABASE_USER: &str = "lemmy";
+pub(in crate::settings) static DEFAULT_DATABASE_PORT: i32 = 5432;
+pub(in crate::settings) static DEFAULT_DATABASE_DB: &str = "lemmy";
+pub static DEFAULT_DATABASE_POOL_SIZE: u32 = 5;
+
 impl Default for DatabaseConfig {
   fn default() -> Self {
     Self {
-      user: "lemmy".into(),
+      user: Some(DEFAULT_DATABASE_USER.to_string()),
       password: "password".into(),
       host: "localhost".into(),
-      port: 5432,
-      database: "lemmy".into(),
-      pool_size: 5,
+      port: Some(DEFAULT_DATABASE_PORT),
+      database: Some(DEFAULT_DATABASE_DB.to_string()),
+      pool_size: Some(DEFAULT_DATABASE_POOL_SIZE),
     }
   }
 }
index d052fec6c665c5db8dbef5c0eb9eca9f7041e6e8..dfdfc59338044de2610cab8c791be387f5037a44 100644 (file)
@@ -1,13 +1,16 @@
 use crate::{
   location_info,
-  settings::structs::{
-    CaptchaConfig,
-    DatabaseConfig,
-    EmailConfig,
-    FederationConfig,
-    RateLimitConfig,
-    Settings,
-    SetupConfig,
+  settings::{
+    defaults::{DEFAULT_DATABASE_DB, DEFAULT_DATABASE_PORT, DEFAULT_DATABASE_USER},
+    structs::{
+      CaptchaConfig,
+      DatabaseConfig,
+      EmailConfig,
+      FederationConfig,
+      RateLimitConfig,
+      Settings,
+      SetupConfig,
+    },
   },
   LemmyError,
 };
@@ -16,7 +19,7 @@ use deser_hjson::from_str;
 use merge::Merge;
 use std::{env, fs, io::Error, net::IpAddr, sync::RwLock};
 
-pub(crate) mod defaults;
+pub mod defaults;
 pub mod structs;
 
 static CONFIG_FILE: &str = "config/config.hjson";
@@ -60,7 +63,15 @@ impl Settings {
     let conf = self.database();
     format!(
       "postgres://{}:{}@{}:{}/{}",
-      conf.user, conf.password, conf.host, conf.port, conf.database,
+      conf
+        .user
+        .unwrap_or_else(|| DEFAULT_DATABASE_USER.to_string()),
+      conf.password,
+      conf.host,
+      conf.port.unwrap_or(DEFAULT_DATABASE_PORT),
+      conf
+        .database
+        .unwrap_or_else(|| DEFAULT_DATABASE_DB.to_string()),
     )
   }
 
index 21d89b98a6b336538616530dc09f6dccf2bd60ad..05c7ed476da534399571e0da6115833924b18cbc 100644 (file)
@@ -27,12 +27,12 @@ pub struct CaptchaConfig {
 
 #[derive(Debug, Deserialize, Clone)]
 pub struct DatabaseConfig {
-  pub user: String,
+  pub user: Option<String>,
   pub password: String,
   pub host: String,
-  pub port: i32,
-  pub database: String,
-  pub pool_size: u32,
+  pub port: Option<i32>,
+  pub database: Option<String>,
+  pub pool_size: Option<u32>,
 }
 
 #[derive(Debug, Deserialize, Clone)]
index ef68f1fd42d2ae704f3ee67cbe647c64a9ada90c..bc4f832fe6eee455234e893e6fe89634b550d8f3 100755 (executable)
@@ -8,4 +8,4 @@ set -e
 mkdir -p volumes/pictrs
 sudo chown -R 991:991 volumes/pictrs
 sudo docker build ../../ --file ../dev/volume_mount.dockerfile -t lemmy-dev:latest
-sudo docker-compose up -d
+sudo docker-compose up
index 0cb036247186a2a9d86750bd10a19dd3dfbcb0b5..38e019f7f52f5070e571c3f8ca7b5c7f56be6192 100644 (file)
@@ -24,7 +24,6 @@ RUN apt-get update -y
 RUN apt-get install -y libpq-dev espeak 
 
 # Copy resources
-COPY config/defaults.hjson /config/defaults.hjson
 COPY --from=rust /app/lemmy_server /app/lemmy
 
 EXPOSE 8536
index 5b8a7ec1d1bf2ee7f6e88a0007bca6f3ecd9169e..0e3cb49ff03df04f1a2e57b5f05556e7ba0778a1 100644 (file)
@@ -16,7 +16,7 @@ use lemmy_routes::{feeds, images, nodeinfo, webfinger};
 use lemmy_server::{api_routes, code_migrations::run_advanced_migrations, scheduled_tasks};
 use lemmy_utils::{
   rate_limit::{rate_limiter::RateLimiter, RateLimit},
-  settings::structs::Settings,
+  settings::{defaults::DEFAULT_DATABASE_POOL_SIZE, structs::Settings},
   LemmyError,
 };
 use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
@@ -38,7 +38,12 @@ async fn main() -> Result<(), LemmyError> {
   };
   let manager = ConnectionManager::<PgConnection>::new(&db_url);
   let pool = Pool::builder()
-    .max_size(settings.database().pool_size)
+    .max_size(
+      settings
+        .database()
+        .pool_size
+        .unwrap_or(DEFAULT_DATABASE_POOL_SIZE),
+    )
     .build(manager)
     .unwrap_or_else(|_| panic!("Error connecting to {}", db_url));