vdb Docs Configuration

Configuration

vdb works with zero configuration — db/schema.rb is parsed automatically and auth is disabled by default. Use the initializer to customise behaviour.

Reference

Option Type Default Description
username String | nil nil HTTP Basic Auth username. Set both username and password to enable auth. Either one alone is ignored.
password String | nil nil HTTP Basic Auth password. Compared using ActiveSupport::SecurityUtils.secure_compare.
databases Hash<String, Pathname|String|nil> { 'primary' => nil } Schema files to expose. Each key becomes a tab label. A nil value auto-resolves to db/schema.rb.
title String 'Database ERD' Text shown in the browser tab and page header.

Initializer

Create config/initializers/vdb.rb with a Vdb.configure block:

# config/initializers/vdb.rb

return unless Rails.env.development?

Vdb.configure do |c|
  c.username  = ENV.fetch('VDB_USER', nil)
  c.password  = ENV.fetch('VDB_PASS', nil)
  c.databases = { 'primary' => nil }
  c.title     = 'Database ERD'
end
Note Always guard the initializer with return unless Rails.env.development?. vdb controllers already check the environment, but keeping sensitive config out of production processes is good hygiene.

Authentication

HTTP Basic Auth is enabled when both username and password are non-nil. The comparison uses Rails' secure_compare to prevent timing attacks.

Vdb.configure do |c|
  c.username = ENV.fetch('VDB_USER')   # e.g. "admin"
  c.password = ENV.fetch('VDB_PASS')   # e.g. "s3cr3t"
end

Set the environment variables in your shell or .env file:

export VDB_USER=admin
export VDB_PASS=s3cr3t
Warning Never hard-code credentials in the initializer. Use environment variables or Rails credentials (rails credentials:edit).

Multiple schema files

If your app uses multiple databases (e.g. primary + a separate audit database), expose each schema as a named tab:

Vdb.configure do |c|
  c.databases = {
    'primary' => nil,   # auto-resolves to db/schema.rb
    'audit'   => Rails.root.join('db', 'audit_schema.rb'),
    'shard'   => Rails.root.join('db', 'shard_schema.rb')
  }
end

Each key appears as a clickable tab in the header. The URL parameter ?database=audit selects the tab directly, which is useful for deep-linking from Slack or a wiki.

URL routing

URLWhat it shows
/dev/erdFirst (or only) database tab
/dev/erd?database=auditaudit tab
/dev/erd?database=shardshard tab
/dev/erd/parseJSON API — schema text → graph data

Custom title

The title appears in the browser tab and in the top-left header of the ERD page:

Vdb.configure do |c|
  c.title = 'Acme Corp — Database ERD'
end

Resetting config

In tests or when you need a clean slate:

Vdb.reset_config!

This restores all options to their defaults.


Ruby API

MethodDescription
Vdb.configure { |c| ... } Block-based configuration. Yields a Vdb::Config instance.
Vdb.config Returns the current Vdb::Config object.
Vdb.reset_config! Replaces the config with a fresh default instance.
vdb v0.1.0 — MIT License — GitHub