Example App
The example/ directory in the vdb repository is a self-contained Rails 8 blog application that ships with vdb pre-wired. It demonstrates every feature of the gem on a realistic seven-table schema.
Run it yourself
cd example && bundle install && bin/rails db:migrate db:seed && bin/rails server
— then open http://localhost:3000/dev/erd.
Schema
The blog models a content platform with authors, expert reviewers, posts, threaded comments, and taxonomy tags.
users ──< posts ──< reviews >── reviewers ──> users
│ │
└──< comments (self-referential: parent_id)
│
post_tags >── tags
users
namestring
emailstring
biotext
rolestring
avatar_urlstring
verified_atdatetime
posts
user_idinteger
titlestring
bodytext
statusstring
featuredboolean
published_atdatetime
reviewers
user_idinteger
specializationstring
biotext
ratingdecimal
verified_atdatetime
reviews
post_idinteger
reviewer_idinteger
ratinginteger
contenttext
approvedboolean
approved_atdatetime
comments
post_idinteger
user_idinteger
parent_idinteger
bodytext
tags
namestring
slugstring
colorstring
post_tags
post_idinteger
tag_idinteger
Notable relationship patterns this schema exercises:
- 1:N —
users → posts,posts → reviews,posts → comments - 1:1 —
users ↔ reviewers(unique index onreviewers.user_id) - N:M via join table —
posts ↔ tagsthroughpost_tags - Self-referential —
comments.parent_idfor threaded replies - Inferred FK —
comments.parent_idnot inadd_foreign_key; vdb infers it automatically
vdb integration
Gemfile
group :development do
gem 'vdb', path: '..' # path reference to parent gem directory
end
config/routes.rb
Rails.application.routes.draw do
mount Vdb::Engine, at: '/dev/erd'
root 'posts#index'
resources :posts, only: %i[index show]
resources :users, only: %i[index show]
resources :reviewers, only: %i[index show]
end
config/initializers/vdb.rb
return unless Rails.env.development?
Vdb.configure do |c|
c.databases = { 'primary' => nil } # auto-resolves to db/schema.rb
c.title = 'Blog ERD — vdb example'
end
Sample data
db/seeds.rb loads a realistic dataset so you can explore the app immediately after setup:
| Record type | Count | Notable details |
|---|---|---|
| Users | 4 | Alice, Bob, Carol (editor), Dave — different roles |
| Reviewers | 3 | Bob (Performance), Carol (Database), Dave (Security) — verified |
| Posts | 4 | 3 published, 1 draft — covering Rails, RSpec, PostgreSQL, JWT |
| Tags | 6 | Ruby, Rails, Performance, Database, Testing, Security |
| Post-tag joins | 12 | 3 tags per post |
| Reviews | 4 | Ratings 4–5, mixed approved status |
| Comments | 4 | Includes one threaded reply (parent_id set) |
ERD screenshots
Full ERD — all tables
All seven tables rendered by D3's force simulation. FK columns are highlighted in cyan. Crow's-foot and single-tick markers indicate cardinality.
Table search
Typing
post in the search box immediately dims non-matching tables. posts and post_tags stay fully visible; everything else fades back.Relationship highlighting
Clicking a table header highlights it and all its direct relationships. Unrelated tables dim so you can trace connections without distraction.
Application pages
Posts index — author, tags, review count
Post detail — reviews with ratings, threaded comments
Users — reviewer badge for credentialed users
Reviewers — specialization, rating, verified status
Run the example
cd example
bundle install
bin/rails db:migrate
bin/rails db:seed
bin/rails server
Then visit:
| URL | Page |
|---|---|
http://localhost:3000 | Posts index |
http://localhost:3000/users | Users list |
http://localhost:3000/reviewers | Reviewers list |
http://localhost:3000/dev/erd | Database ERD |