Skip to content

Use Hanami::DB::DatabaseURL in db commands - #463

Draft
parndt wants to merge 4 commits into
mainfrom
database-url-helpers
Draft

parndt wants to merge 4 commits into
mainfrom
database-url-helpers

Conversation

@parndt

@parndt parndt commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Depends on hanami/hanami-db#26, which should be merged first. Part of hanami/hanami-db#25.

hanami db commands now use hanami-db's new Hanami::DB::DatabaseURL to recognise database URLs, including JRuby's JDBC URLs. This replaces their own JDBC prefix handling and scheme aliases.

Changes

  • Shared URL handling: Utils::Database.database_class resolves the database class from DatabaseURL.adapter. The JDBC handling in Database#database_uri and Sqlite#name now uses the same helpers.
  • Clearer errors: unsupported schemes now raise the existing, previously unused, UnsupportedDatabaseSchemeError rather than a RuntimeError. URLs that can't be parsed raise a new InvalidDatabaseURLError rather than URI::InvalidURIError. Neither error includes the URL or carries the URI error as its cause, since the URL may contain credentials.
  • Version check: hanami-db is an optional dependency, so the gemspec can't require a minimum version of it. If the installed hanami-db doesn't provide DatabaseURL, hanami db commands raise a new HanamiDBVersionError explaining how to upgrade. hanami-db is only required when a db command runs, since every app command loads utils/database.rb.

Before merging

Replace the db utils' own JDBC URL handling and scheme aliases with the shared
helper from hanami-db (hanami/hanami-db#25).

hanami-db is required only when resolving a database class, rather than at the
top of utils/database.rb, since every app command loads that file, including in
apps that do not use hanami-db (an optional dependency of hanami-cli).
Raise the existing (previously unused) UnsupportedDatabaseSchemeError for
unsupported schemes, and a new InvalidDatabaseURLError for URLs that cannot
be parsed, rather than a RuntimeError or URI::InvalidURIError.

Neither includes the URL in its message, nor carries the URI error as its
cause, since the URL may contain credentials.
hanami-db is an optional dependency, so hanami-cli's gemspec cannot require a
minimum version of it. Apps upgrading hanami-cli while keeping an older
hanami-db would otherwise hit a NameError for Hanami::DB::DatabaseURL when
running `hanami db` commands.

This matches the equivalent check in hanami's db provider.
Temporary, until hanami/hanami-db#25's changes are merged. Revert before merging.
@parndt
parndt force-pushed the database-url-helpers branch from ac04253 to 6ce46d5 Compare October 20, 2026 04:15
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.

1 participant