Skip to content

fix: database.url config takes precedence over DATABASE_URL env var#309

Merged
NiklasRosenstein merged 4 commits into
developfrom
copilot/fix-database-url-settings
May 22, 2026
Merged

fix: database.url config takes precedence over DATABASE_URL env var#309
NiklasRosenstein merged 4 commits into
developfrom
copilot/fix-database-url-settings

Conversation

Copilot AI commented May 21, 2026

Copy link
Copy Markdown
Contributor
  • Fix database.url config taking precedence over DATABASE_URL env var in src/server/settings.rs
  • Update docs/engineering/…/configuration.md to reflect corrected precedence
  • Add DATABASE_URL at Compile Time section to docs/engineering/…/developer-guide.md explaining that DATABASE_URL is required at compile time for SQLx query verification (with example commands), and that the runtime URL comes from settings.database.url
  • Update configuration.md note to cross-reference the developer guide instead of restating the compile-time detail

The DATABASE_URL env var was unconditionally overriding database.url from
the config file. It is now only used as a fallback when database.url is
not set. Also add Default derive to DatabaseSettings and serde(default)
to the database field so the section can be omitted entirely.

Agent-Logs-Url: https://github.com/rise-deploy/rise/sessions/ffd4f056-2685-448e-a57e-5ee6f771fbe3

Co-authored-by: NiklasRosenstein <1318438+NiklasRosenstein@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix database.url setting to work with DATABASE_URL env var fix: database.url config takes precedence over DATABASE_URL env var May 21, 2026
Copilot AI requested a review from NiklasRosenstein May 21, 2026 16:32

@NiklasRosenstein NiklasRosenstein left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Does SQLX understand the database.url setting? I don't see how we tell SQLX about that URL at runtime.

Copilot AI commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Does SQLX understand the database.url setting? I don't see how we tell SQLX about that URL at runtime.

Yes — settings.database.url is passed directly to SQLx at runtime in AppState::new() (src/server/state.rs:242):

let db_pool = PgPoolOptions::new()
    .max_connections(10)
    .connect(&settings.database.url)   // ← uses the resolved config value
    .await
    .context("Failed to connect to PostgreSQL")?;

DATABASE_URL is only needed at compile time for SQLx's query! macro verification. At runtime the connection URL comes entirely from settings.database.url, which is now resolved in this order:

  1. database.url from the config file (including ${VAR} substitution)
  2. DATABASE_URL env var as a fallback (if database.url is empty/absent)

@NiklasRosenstein

Copy link
Copy Markdown
Contributor

@copilot Great. The we should find a real good place to document that DATABASE_URL is required at compile time / for sqlx prepare. Probably on the developer side, less so on the operator side.

Copilot AI commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Great. The we should find a real good place to document that DATABASE_URL is required at compile time / for sqlx prepare. Probably on the developer side, less so on the operator side.

Done in 0a9dd96. Added a "DATABASE_URL at Compile Time" subsection to the SQLX section in developer-guide.md explaining that DATABASE_URL must point to a live, migrated PostgreSQL instance when running cargo sqlx prepare, and that at runtime the URL comes from settings.database.url. The note in configuration.md now cross-references that section instead of repeating the detail.

@NiklasRosenstein NiklasRosenstein marked this pull request as ready for review May 21, 2026 18:35
@github-actions

github-actions Bot commented May 21, 2026

Copy link
Copy Markdown

Docs preview: /preview/pr-309/

Updated for commit e40e4ce.

The database section is now optional (#[serde(default)]), so it is no
longer in the schema's required list. Regenerated to keep the committed
schema in sync, which CI verifies via config:schema:check.

https://claude.ai/code/session_01TmD3FqbNZqmKsM36WmJzxD
@NiklasRosenstein NiklasRosenstein merged commit 439aeaf into develop May 22, 2026
17 checks passed
@NiklasRosenstein NiklasRosenstein deleted the copilot/fix-database-url-settings branch May 22, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting database.url in settings doesn't actually work, DATABASE_URL env var is used

3 participants