#1526·hanami

Presence of `db/` directory auto-registers DB provider even when not wanted

Author: aaronmallenCreated Jul 2, 2025Updated Jul 28, 2026

When an app or parent slice has a db/ directory, Hanami automatically registers a DB provider and tries to inject db.rom, even when you don't want the parent tied to a database.

Expected Behavior

Having a db/ directory should not automatically require database configuration. You should be able to define the db module structure for child slices to inherit without forcing the parent to configure a database connection.

Current Behavior

The presence of a db/ directory causes Hanami to assume database functionality is needed and automatically registers the DB provider, requiring database configuration even when none is wanted.

Steps to Reproduce

  1. Create an app/slice with a db/ directory (for module structure)
  2. Don't configure any database connection in that app/slice
  3. Try to boot the app/slice
  4. Error: A database_url for gateway default is required to start :db

Use Case

You want to define a db module structure that child slices can inherit from, but you don't want the parent app/slice itself to require database configuration.

Root Cause

In lib/hanami/slice.rb, the register_db_provider? method checks:

ruby

ruby
def register_db_provider?
  concrete_db_provider? ||
  db_config_dir? ||
  relations_dir? ||
  db_source_dir? ||  # <-- This line causes the issue
  import_db_from_parent?
end

The db_source_dir? check returns true when the parent has a db/ directory, causing child slices to automatically register a DB provider even when they don't need one.

Environment

  • Hanami version: 2.2
  • Multi-slice architecture where parent defines db module structure but doesn't need database connection

Related to PR #1490