Repository navigation
feat: DATABASE_URL in the bound resolver, app pools on it, and service providers in generated apps - #13
Conversation
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.
Review — feat: DATABASE_URL in the bound resolver, app pools on it, generated-app providersDecision: NEEDS_FIX (2 medium, small-effort items). No blocking issues. Verified
Should fix
Nits
Security note (pre-existing, now fed by env URLs)
What CI does not proveGenerated app code is not compiled in CI; the generated |
- 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.
|
@vheins, thanks for the review. Every point is addressed:
|
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
fix(rustasea): honour DATABASE_URL in the bound connection resolverDATABASE_URL(thenDATABASE__URL) replaces the default connection in the resolverDatabaseServiceProviderbinds, 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 resolverresolve_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 appsdocs: sync status docs with #12 as merged and record the service wiringservices.rspointed at the wrong lines (two inREADME.mdtoo). 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.database_urlconfig key is gone. No shipped config or template sets it; the CLI still reads it.DATABASE_URLdelays startup by the pool's acquire timeout.Testing
On rustc 1.100.0:
cargo xtask cipasses (731 files within the line limit).cargo test --workspace --no-fail-fastpasses (191 suites, 1985 tests), including the generated-app compile check for all five variants;cargo test -p rustasea-storage --features aws,sftppasses.crates/rustasea/tests/services_database_url.rs:DATABASE_URLreplaces the default connection only, and resolving opens that database.DATABASE_URLpointing at a scratch SQLite file: it opened that file and created nodatabase.sqlite.Two files near the 500-line limit were split rather than grown:
scaffold/templates/core.rs(498,lib.rs/main.rstemplates moved toentry.rs) andapp/bootstrap/auth.rs(tests moved toauth/tests.rs).Not in this PR
Wiring
DatabaseUserProviderinto the scaffold templates (M3) is left out: generated apps have no login flow to wire it into yet. Their auth controllers and theattemptaction aretodo!()stubs (templates/app_http.rs,templates/app_auth.rs), so that needs the generated auth flow first.docs/milestones.mdrecords the reason.@vheins, could you review this?