Skip to content

Elysium-Arc/Rails-Modeler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rails Modeler

Generate Mermaid ER diagrams from your Rails model associations and schema.

Unlike schema-only tools, Rails Modeler reads has_many, has_one, belongs_to, and has_and_belongs_to_many declarations via Rails' Reflection API, and extracts attributes from db/schema.rb.

Installation

Add to your Gemfile:

gem "rails_modeler", group: :development

Then run:

bundle install

Usage

Generate the diagram:

rake rails_modeler:generate

This writes a .mmd file (default: docs/schema.mmd) and prints the diagram to stdout.

Configuration

Create an initializer at config/initializers/rails_modeler.rb:

RailsModeler.configure do |config|
  config.excluded_models = ["ActiveStorage::Blob", "ActiveStorage::Attachment"]
  config.output_path = "docs/er_diagram.mmd"
  config.show_attributes = true
  config.title = "My App Schema"
end
Option Default Description
excluded_models [] Model names to omit from the diagram
output_path "docs/schema.mmd" Where to write the .mmd file
show_attributes true Include column attributes in entity blocks
title "Schema" Diagram title

Example Output

erDiagram
    Author {
        integer id PK
        string name
    }
    Article {
        integer id PK
        string title
        integer author_id FK
    }
    Author ||--o{ Article : "has_many"
Loading

Supported Associations

  • belongs_to (including polymorphic)
  • has_many (including as: polymorphic)
  • has_one
  • has_and_belongs_to_many

Bidirectional associations are automatically deduplicated.

Development

bundle install
bundle exec rspec

License

MIT License. See LICENSE.txt.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages