Skip to content

feat: DATABASE_URL in the bound resolver, app pools on it, and service providers in generated apps - #13

Merged
vheins merged 8 commits into
rustasea:masterfrom
gitfromwildan:feat/scaffold-services-and-resolver
Nov 21, 2026
Merged

vheins merged 8 commits into
rustasea:masterfrom
gitfromwildan:feat/scaffold-services-and-resolver

Conversation

@gitfromwildan

Copy link
Copy Markdown
Contributor

Summary

Finishes the M0 service wiring from #12 and brings the status docs back in line with the merged code. Based on master; independent of the ORM follow-up PR.

Changes

Commit Effect
fix(rustasea): honour DATABASE_URL in the bound connection resolver DATABASE_URL (then DATABASE__URL) replaces the default connection in the resolver DatabaseServiceProvider binds, as it already does for the CLI. Without it, everything on the bound resolver, including the database queue connections from #12, ignored the variable.
refactor(app): open the user provider and queue dashboard pools through the bound resolver Both opened their own pool via a private copy of the CLI's URL rules (resolve_database_url, now removed). The app now has one place that decides which database it uses.
feat(scaffold): register the framework service providers in generated apps Generated apps register the three providers and connect their database queue connections after boot, like the runnable app.
docs: sync status docs with #12 as merged and record the service wiring #12's docs commit was not part of the merge, so citations into the dispatcher, host dispatch, the JWT guard, the shutdown module, and services.rs pointed at the wrong lines (two in README.md too). Repointed, with descriptions matching the merged code.

Behaviour changes

  • DATABASE_URL: the bound resolver now uses it for the default connection; other named connections and pool settings are kept.
  • Runnable app: the fallback to a top-level database_url config key is gone. No shipped config or template sets it; the CLI still reads it.
  • Generated apps: they open the default database at boot to register the database queue connections. With the shipped SQLite default this is immediate; an unreachable database pointed at by DATABASE_URL delays startup by the pool's acquire timeout.

Testing

On rustc 1.100.0:

  • cargo xtask ci passes (731 files within the line limit).
  • cargo test --workspace --no-fail-fast passes (191 suites, 1985 tests), including the generated-app compile check for all five variants; cargo test -p rustasea-storage --features aws,sftp passes.
  • New test binary crates/rustasea/tests/services_database_url.rs: DATABASE_URL replaces the default connection only, and resolving opens that database.
  • Started the app with DATABASE_URL pointing at a scratch SQLite file: it opened that file and created no database.sqlite.

Two files near the 500-line limit were split rather than grown: scaffold/templates/core.rs (498, lib.rs/main.rs templates moved to entry.rs) and app/bootstrap/auth.rs (tests moved to auth/tests.rs).

Not in this PR

Wiring DatabaseUserProvider into the scaffold templates (M3) is left out: generated apps have no login flow to wire it into yet. Their auth controllers and the attempt action are todo!() stubs (templates/app_http.rs, templates/app_auth.rs), so that needs the generated auth flow first. docs/milestones.md records the reason.

@vheins, could you review this?

The database service provider built its resolver from [database] alone, so a
DATABASE_URL in the environment was ignored by everything that uses the bound
resolver, including the database queue connections. The CLI and the runnable
app both let DATABASE_URL (then DATABASE__URL) win.

The provider now points the default connection at that URL, keeping the other
named connections and the pool settings. Tested in its own binary, since the
variable is process-global.
…gh the bound resolver

Both opened their own pool from a URL resolved by a private copy of the
CLI's precedence rules (resolve_database_url). They now use the connection
resolver that DatabaseServiceProvider binds at boot, which applies the same
DATABASE_URL / DATABASE__URL override, so the app opens one pool per
connection and has a single place that decides which database it uses.
resolve_database_url is removed; its fallback to a top-level database_url
key is dropped, as no shipped config or template sets it.

Checked by starting the app with DATABASE_URL pointing at a scratch SQLite
file: it opened that file and created no database.sqlite.

bootstrap/auth.rs was at 476 lines; its tests move to bootstrap/auth/tests.rs
to keep it clear of the 500-line limit.
… apps

Generated apps now register DatabaseServiceProvider, CacheServiceProvider,
and QueueServiceProvider ahead of their own providers, and their main.rs
connects the database queue connections after boot, as the runnable app
does. The generated-app compile test covers all five variants.

templates/core.rs was at 498 lines; the lib.rs and main.rs templates move to
templates/entry.rs to keep it clear of the 500-line limit.
…ice wiring

rustasea#12 merged with different review follow-ups than the ones its docs commit
described, and that docs commit was not part of the merge, so citations into
the dispatcher, host dispatch, the JWT guard, the shutdown module, and
services.rs pointed at the wrong lines (two in README.md as well). They are
repointed, and the descriptions now match the merged code: exact domains
before {name} domains, logout revoking from an expired access token, and the
GracefulShutdown guard.

M0 records DATABASE_URL support in the bound resolver, the app's pools going
through it, and generated apps registering the providers, and drops those
items from Partial, Missing, and Next actions. M3 notes why the scaffold's
database user provider item is still open: generated apps have no login flow
to wire it into yet. Changelog entries for both.
@github-actions
github-actions Bot requested a review from vheins November 21, 2026 11:31
@vheins

vheins commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Review — feat: DATABASE_URL in the bound resolver, app pools on it, generated-app providers

Decision: NEEDS_FIX (2 medium, small-effort items). No blocking issues.

Verified

  • DATABASE_URL → DATABASE__URL → [database] default precedence matches the CLI (services.rs:88-94 vs migration.rs:18-22), including the non-blank filter.
  • The override touches only the default connection: other named connections and the effective pool survive (services.rs:98-113); services_database_url.rs asserts main is replaced, jobs kept, and that resolve(None) opens the env database and not the configured one.
  • Unset DATABASE_URL is a no-op; the sqlite default (config/database.toml:11-23) is unchanged.
  • auth.rs / app.rs now resolve through the bound resolver; fail-closed semantics (UnsupportedDriver, unreachable, missing users table) are unchanged; tests moved to auth/tests.rs via mod tests; with resolver-based setup.
  • core.rs → entry.rs split is content-preserving (LIB_RS byte-identical; MAIN_RS differs only by the queue-connection block). Line counts all under 500: core 422, entry 86, app 391, auth 400, services 205.
  • Generated-provider list mirrors the runnable app (bootstrap.rs:70-83 vs providers.rs:199-210).
  • All re-pointed doc citations resolve to the claimed symbols (services, auth, main, dispatch, jwt, host, shutdown, bootstrap, entry).

Should fix

  1. Malformed [database] shadows DATABASE_URL. DatabaseServiceProvider parses config first and only applies the override on success, so a config-parse error leaves the resolver unbound and DATABASE_URL ignored — unlike the CLI and unlike the previous app helper. Fix: when from_loader errors and DATABASE_URL/DATABASE__URL is set, bind a resolver over an empty config with the override applied.
  2. Disclose the generated-app boot-time DB dependency. Generated apps await connect_database_queues before serving, and the shipped default queue is database, so every generated app opens the default DB at boot; an unreachable DB stalls boot up to the 30 s acquire timeout and the app then serves with those queue drivers unregistered (entry.rs:38, db.rs:20-21). Add that to the CHANGELOG entry.

Nits

  • Test only covers DATABASE_URL set; add DATABASE__URL, blank, and unset cases. PID-keyed scratch names can flake on a stale file.
  • The override drops a default connection's read/write/charset silently; document or carry them forward.

Security note (pre-existing, now fed by env URLs)

DbPool::connect_with_settings echoes the full URL (incl. credentials) for an unknown scheme; mariadb://user:pass@… passes Driver validation and is rejected there, printing the password. Recommend redacting the URL in that error.

What CI does not prove

Generated app code is not compiled in CI; the generated main.rs path to rustasea::services::connect_database_queues was verified statically (public services module, facade always links orm/queue/cache, configure(|_| {}) mounts config).

- env override now applies even when [database] fails to parse (matches the CLI)
- tests cover DATABASE__URL, blank, and unset plus unique scratch names
- doc notes that the override replaces the default connection wholesale
…ated apps

- Disclose the boot-time database dependency of generated apps
  Generated apps open the default database at boot to register database queue
  connections, so an unreachable database delays startup by up to the pool
  acquire timeout before the app serves with those connections unregistered.
…rride case

The config loader coerces `default = 123` to the string "123", so the table
parsed and the override landed on a connection named "123"; the case never
reached the malformed-config branch and failed on the missing "default" key.
DbPool::connect_with_settings echoed the full URL when the scheme was not
sqlite, postgres, or mysql, so a URL such as mariadb://user:pass@host printed
its password. Now that DATABASE_URL feeds the bound resolver, that URL can
come from the environment. The error names only the scheme.
@gitfromwildan

Copy link
Copy Markdown
Contributor Author

@vheins, thanks for the review. Every point is addressed:

Review point Commit
Should fix 1: malformed [database] shadows DATABASE_URL 287f949 binds a resolver from an empty config with the override applied when parsing fails
Should fix 2: boot-time DB dependency of generated apps 473b80b documents it in the CHANGELOG entry and the generated README
Nit: test cases and scratch names 287f949 adds DATABASE__URL, blank, unset, and malformed-config cases, and adds a counter and timestamp to the scratch names
Nit: read/write/charset dropped 287f949 documents that the override replaces the default connection wholesale
Security note: URL echoed for an unknown scheme d2c4e67 makes the error name only the scheme; a unit test checks that a mariadb://user:pass@… URL does not leak the password

b128fb4 fixes the CI failure on 287f949. The malformed-config case used default = 123, which the config loader coerces to the string "123", so the table parsed and the case never reached the error branch. It now uses connections = "not-a-table", which fails to deserialize.

@vheins
vheins merged commit d7cc118 into rustasea:master Nov 21, 2026
6 checks passed
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.

2 participants