Your Rails schema, alive.
Schema ERD turns db/schema.rb into an interactive database map inside your Rails app. Mount one Rack endpoint and get a canvas you can search, pan, zoom, rearrange, and explore—without Graphviz, Node, model loading, or a build step.
# config/routes.rb
mount SchemaErd::App.new(schema_path: Rails.root.join("db/schema.rb")), at: "/rails/erd"Open /rails/erd. That is the whole setup.
Most ERD tools generate an artifact. Schema ERD gives you a workspace.
- Reads the source of truth. Tables, columns, indexes, defaults, null constraints, primary keys, and foreign keys come straight from
db/schema.rb. - Feels immediate. Refresh the page after a migration; there is nothing to regenerate.
- Handles real schemas. Search tables and columns, hide Rails internals, toggle detail, and fit the entire graph to the window.
- Makes relationships navigable. Click a table to isolate its references and dependents. The selected table lives in the URL, ready to paste into a pull request or team chat.
- Gets out of your way. Drag cards into place, pan the canvas, zoom with the controls or keyboard, and let local storage remember the layout.
- Ships almost nothing. The rendered page is standalone HTML, CSS, and JavaScript. The gem has no runtime dependencies.
Schema ERD is a development tool. Keep it out of production:
# Gemfile
group :development do
gem "schema_erd"
endThen mount it behind a development-only route:
# config/routes.rb
Rails.application.routes.draw do
mount SchemaErd::App.new(schema_path: Rails.root.join("db/schema.rb")), at: "/rails/erd" if Rails.env.development?
endRun bundle install, boot Rails, and visit http://localhost:3000/rails/erd.
| Action | Control |
|---|---|
| Find a table or column | Search box |
| Focus a table and its neighbors | Click its header |
| Move a table | Drag its header |
| Pan | Drag empty canvas space |
| Zoom | Buttons, + / -, or Ctrl/⌘ + wheel |
| Reset zoom | 0 |
| Fit the diagram | F |
| Leave focused view | Esc or “Show all tables” |
Layout positions are stored in the browser and keyed by the schema version. A new migration gets a fresh layout; older layouts stay intact.
Schema ERD recognizes common framework-owned tables such as Active Storage, sessions, ar_internal_metadata, and schema_migrations. They are visible by default and can be hidden from the controls.
- Ruby 3.2 or newer.
- A Rails-style Ruby schema file (
db/schema.rb). - Any Rack-compatible Rails version capable of mounting an object that responds to
call.
structure.sql is not supported. Schema ERD parses the stable shape of Rails-generated Ruby schema files; it does not execute the schema or boot your models.
The app is an ordinary Rack endpoint, so Rails is convenient rather than required:
require "schema_erd"
run SchemaErd::App.new(schema_path: File.expand_path("db/schema.rb", __dir__))The parser is public too:
schema = SchemaErd::Parser.call(File.read("db/schema.rb"))
schema.tables.first.name
schema.relationships.first.from_tableAn ERD exposes table and column names. Mount it only where intended—normally in development—and add your own authentication if you expose it in a shared environment. Responses are marked no-store and noindex, nofollow, but those headers are not access control.
bundle install
bundle exec rake
bundle exec rake buildBug reports and focused pull requests are welcome. Please include a minimal schema.rb fragment when reporting parser behavior.
Schema ERD is available under the MIT License.