Read database, host and SMTP settings from a .env file

- gem dotenv loads .env (and .env.<environment>[.local]) at startup; real
  environment variables take precedence.
- database.yml takes host, port, user, password and name from
  NUMOLUS_DATABASE_*; the database is called numolus by default.
- .env.example documents every setting; .env itself stays ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
wkh
2026-09-28 20:57:43 +02:00
co-authored by Claude Opus 5.5
parent ed099cfbda
commit f22963a666
6 changed files with 49 additions and 13 deletions
+26
View File
@@ -0,0 +1,26 @@
# numolus settings -- copy to .env (same directory) and fill in.
# .env is read at startup (gem dotenv) and never committed. Variables that
# are already set in the real environment take precedence over this file.
# Environment-specific files are read too: .env.production, .env.development
# (and *.local variants).
# ---- Database (PostgreSQL) --------------------------------------------------
# Unset host/user/password = local socket as the current OS user (development).
NUMOLUS_DATABASE_NAME=numolus
NUMOLUS_DATABASE_HOST=localhost
NUMOLUS_DATABASE_PORT=5432
NUMOLUS_DATABASE_USER=numolus
NUMOLUS_DATABASE_PASSWORD=
# ---- Server -------------------------------------------------------------------
# Host name used in links in mails (sign-in, invitations)
NUMOLUS_HOST=numolus.wicom.li
# Rails secret (production): generate with bin/rails secret
SECRET_KEY_BASE=
# ---- Mail (production; development shows mails at /letter_opener) ------------
NUMOLUS_MAIL_FROM="numolus <noreply@wicom.li>"
SMTP_ADDRESS=smtp.example.com
SMTP_PORT=587
SMTP_USER_NAME=
SMTP_PASSWORD=
+1
View File
@@ -26,4 +26,5 @@ node_modules
!/storage/.keep
/config/master.key
/.env*
!/.env.example
/vendor/gems
+4
View File
@@ -37,6 +37,10 @@ group :development do
gem "web-console"
end
# Settings and secrets (database, SMTP, host) from a .env file in the project
# directory; real environment variables win -- see .env.example
gem "dotenv"
# Vite as the frontend build, integrated into Rails [https://vite-ruby.netlify.app]
gem "vite_rails"
+2
View File
@@ -97,6 +97,7 @@ GEM
debug (1.11.1)
irb (~> 1.10)
reline (>= 0.3.8)
dotenv (3.2.0)
drb (2.2.3)
dry-cli (1.4.1)
erb (6.0.7)
@@ -300,6 +301,7 @@ DEPENDENCIES
brakeman
bundler-audit
debug
dotenv
letter_opener_web
pg (~> 1.1)
puma (>= 5.0)
+6 -5
View File
@@ -28,11 +28,12 @@ kommen über ActionCable sofort bei den anderen an (Yjs, siehe
[`app/frontend/collab/`](app/frontend/collab/)), jede Person hat ihr eigenes
Undo, und die Auswahl der anderen ist als farbiger Rahmen zu sehen. Details: [`docs/konzept-teilen-und-zusammenarbeit.md`](docs/konzept-teilen-und-zusammenarbeit.md).
Mails landen in der Entwicklung nicht im Postfach, sondern unter
<http://localhost:3000/letter_opener>. Produktion braucht `SMTP_ADDRESS`,
`SMTP_USER_NAME`, `SMTP_PASSWORD`, `NUMOLUS_MAIL_FROM`, `NUMOLUS_HOST` und
`NUMOLUS_DATABASE_PASSWORD`; Solid Queue, Cache und Cable liegen in derselben
Datenbank wie die Daten.
**Konfiguration:** Datenbank-Zugang, Server-Name, SMTP und `SECRET_KEY_BASE`
stehen in einer `.env` im Projektverzeichnis – Vorlage kopieren und ausfüllen:
`cp .env.example .env`. Die Datei wird nie committet; echte
Umgebungsvariablen haben Vorrang. Solid Queue, Cache und Cable liegen in
derselben Datenbank wie die Daten. Mails landen in der Entwicklung nicht im
Postfach, sondern unter <http://localhost:3000/letter_opener>.
---
+10 -8
View File
@@ -15,14 +15,17 @@
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
# Connection details come from the environment, usually a .env file in
# the project directory (see .env.example). Unset = local socket, own user.
host: <%= ENV["NUMOLUS_DATABASE_HOST"] %>
port: <%= ENV["NUMOLUS_DATABASE_PORT"] %>
username: <%= ENV["NUMOLUS_DATABASE_USER"] %>
password: <%= ENV["NUMOLUS_DATABASE_PASSWORD"] %>
development:
<<: *default
database: numolus_development
database: <%= ENV.fetch("NUMOLUS_DATABASE_NAME", "numolus") %>
# The specified database role being used to connect to PostgreSQL.
# To create additional roles in PostgreSQL see `$ createuser --help`.
@@ -59,9 +62,8 @@ test:
database: numolus_test
# Production: one database for everything -- app data, Solid Queue, Solid
# Cache and Solid Cable. The password comes from NUMOLUS_DATABASE_PASSWORD.
# Cache and Solid Cable. Credentials via NUMOLUS_DATABASE_* (see .env.example).
production:
<<: *default
database: numolus_production
username: numolus
password: <%= ENV["NUMOLUS_DATABASE_PASSWORD"] %>
database: <%= ENV.fetch("NUMOLUS_DATABASE_NAME", "numolus") %>
username: <%= ENV.fetch("NUMOLUS_DATABASE_USER", "numolus") %>