Code Monkey home page Code Monkey logo

erd's Introduction

Erd

A Rails engine for drawing your app's ER diagram and operating migrations

Requirements

  • Rails 7.0, 6.1, 6.0, 5.2, 5.1, 5.0, 4.2, 4.1, 4.0, 3.2, or 3.1

  • Graphviz

Installation

Bundle 'erd' gem to your existing Rails app's Gemfile:

gem 'erd', group: :development

Usage

Browse at your http://localhost:3000/erd

Features

Show Mode

  • Erd draws an ER diagram based on your app's database and models.

  • You can drag and arrange the positions of each model.

    • Then you can save the positions to a local file db/erd_positions.json, so you can share the diagram between the team members.

Edit Mode

  • You can operate DB schema manipulations such as add column, rename column, alter column, create model (as well as table), and drop table.

  • Then, Erd generates migration files on the server.

  • And you can run each migration on your browser super quickly.

TODO

  • Fix buggy JS

  • drop column (need to think of the UI)

  • stop depending on Graphviz

  • tests

  • cleaner code (the code is horrible. Please don't read the code, though of course your patches welcome)

Contributing to Erd

  • Send me your pull requests!

Team

Copyright

Copyright (c) 2012 Akira Matsuda. See MIT-LICENSE for further details.

erd's People

Contributors

amatsuda avatar lezuse avatar machida avatar nurse avatar os0x avatar rickpr avatar sanfrecce-osaka avatar xiaohui-zhangxh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

erd's Issues

Stack overflow in regexp matcher

Hey Akira!

Got this error on my Mac OS X 10.9.3:
Stack overflow in regexp matcher: /^node ([^ ]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) ([0-9\.]+) <\{?(<((?!^\}?>).)*)^\}?> [^ ]+ [^ ]+ [^ ]+ [^ ]+\n/m
Here is the full stacktrace:
http://pastie.org/9350927

ruby v='1.8.7'
rails v='3.1.12'

Deprecation warnings in erd.css.scss

I get the following messages with Rails 5.2.2:

DEPRECATION WARNING on line 28 of gems/erd-0.6.0/app/assets/stylesheets/erd/erd.css.scss:
The operation `#eeeeee minus 30` is deprecated and will be an error in future versions.
Consider using Sass's color functions instead.
http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions

DEPRECATION WARNING on line 128 of gems/erd-0.6.0/app/assets/stylesheets/erd/erd.css.scss:
The operation `#fffebe minus 6` is deprecated and will be an error in future versions.
Consider using Sass's color functions instead.
http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions

DEPRECATION WARNING on line 375 of gems/erd-0.6.0/app/assets/stylesheets/erd/erd.css.scss:
The operation `#444444 plus 50` is deprecated and will be an error in future versions.
Consider using Sass's color functions instead.
http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions

DEPRECATION WARNING on line 400 of gems/erd-0.6.0/app/assets/stylesheets/erd/erd.css.scss:
The operation `#444444 minus 10` is deprecated and will be an error in future versions.
Consider using Sass's color functions instead.
http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions

DEPRECATION WARNING on line 422 of gems/erd-0.6.0/app/assets/stylesheets/erd/erd.css.scss:
The operation `white minus 6` is deprecated and will be an error in future versions.
Consider using Sass's color functions instead.
http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions

DEPRECATION WARNING on line 490 of gems/erd-0.6.0/app/assets/stylesheets/erd/erd.css.scss:
The operation `white minus 20` is deprecated and will be an error in future versions.
Consider using Sass's color functions instead.
http://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions

Got an undefined method error

Platform:
OS: Mac OS X
Ruby: 1.9.3
Rails: 3.0.5
Graphviz: 2.30.1

Got error:
undefined methodisolate_namespace' for Erd::Engine:Class`

RuntimeError in Erd::ErdController#index

Not sure if this gem is still begin actively developed but I received this error on hitting localhost:3000/erd.

Running Mavericks, Ruby 2.1, Rails 4.1beta, latest Grahpviz from Homebrew.

Saving diagram failed! Graphviz produced errors. Verify it has support for filetype=plain, or use filetype=dot. Original error: 2014-01-31 09:24:41.027 dot[37149:d07] CoreText performance note: Client called CTFontCreateWithName() using name "Arial Italic" and got font with PostScript name "Arial-ItalicMT". For best performance, only use PostScript names when calling this API.

SyntaxError in test env

With rails-3.2.12 and erd-0.3.0, rails cannot bootstrap in RAILS_ENV=test.

For example, rails c test causes an error below:

erd-0.3.0/app/controllers/erd/models_controller.rb:6: syntax error, unexpected '<', expecting keyword_end (SyntaxError)
      <%= render :partial => 'erd/erd/model', :object => model -%>
# Gemfile
group :development, :test do
  gem 'erd'
end

But, with rails 4.0.0, it works fine.

ArgumentError: comparison of NilClass with 0 failed

ArgumentError in Erd::ErdController#index
comparison of NilClass with 0 failed
Extracted source (around line #140):

      }.compact
      max_model_x = models.map {|m| m[:x].to_f + m[:width].to_f }.max
      erd_width = [[(BigDecimal(svg_width) * 72).round, max_model_x].min + 150, 1024].max
      max_model_y = models.map {|m| m[:y].to_f + m[:height].to_f }.max
      erd_height = [[(BigDecimal(svg_height) * 72).round, max_model_y].min + 150, 768].max
      # edge tail head n x1 y1 .. xn yn [label xl yl] style color

License missing from gemspec

Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec
via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Bundler now generates gems with a default 'MIT' license. There is even a License Finder
to help companies ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec.
Including a license in your gemspec is a good practice, in any case.

If you need help choosing a license, github has created a license picker tool

How did I find you?

I'm using a script to collect stats on gems, originally looking for download data, but decided to collect licenses too,
and make issues for gemspecs not specifying a license as a public service :)
So far it's going pretty well.
I've written a blog post about it

Rails 4.2.6 Bug-Fixes

Just began testing with the below fixes, so no guarantees.

  1. Asset names passed to helpers should not include the "/assets/" prefix.
    The error points to app/views/erd/erd/erd.html.erb. I can generate the pdf diagram ok by running 'erd' from the Rails-Root folder. This code pattern has now been made breaking** in Rails 4.2, and affects many files within the gem's install folder. The first to fail was /erd-0.4.0/app/views/erd/erd/_model.html.erb.

My fix was to run the following (adjust to your gem install path):
find .../.rvm/gems/ruby-2.2.1/gems/erd-0.4.0/app/views/erd/erd/ -type f -exec sed -i 's#/assets/erd/#/erd/#g' {} +
find .../.rvm/gems/ruby-2.2.1/gems/erd-0.4.0/app/assets/javascripts/erd/ -type f -exec sed -i 's#/assets/erd/#/erd/#g' {} +
find .../.rvm/gems/ruby-2.2.1/gems/erd-0.4.0/app/assets/stylesheets/erd/ -type f -exec sed -i 's#/assets/erd/#/erd/#g' {} +
find .../.rvm/gems/ruby-2.2.1/gems/erd-0.4.0/vendor/assets/stylesheets/ -type f -exec sed -i 's#/assets/erd/#/erd/#g' {} +

  1. 'Asset filtered out and will not be served:' error.
    This can be fixed by putting the following in /config/initializers/assets
    Rails.application.config.assets.precompile += %w( erd/* )

BTW - great gem, and thank you for creating something that should have been built into Rails since at least version 1.1 - I had this core Gui-functionality at my fingertips 20+ years ago in other environments. Cheers!

** I am not sure why the Rails team thinks it is so imperative to break working, readable code - disregarding thousands of hours of others' lives and making Rails coders look slow and buggy in so doing. Backwards compatibility for reasonable, 5 year periods, would reflect app-lifespans. Maybe they can create their own "Fedorails" to "play" on, and let the rest of us serve our clients?

http://localhost:3000/erd ended with error

[2012-05-01 09:46:34.636] FATAL NoMethodError (undefined method name' for nil:NilClass): rails-erd (0.4.5) lib/rails_erd/domain.rb:102:inblock (2 levels) in relationships_mapping'
rails-erd (0.4.5) lib/rails_erd/domain.rb:100:in each' rails-erd (0.4.5) lib/rails_erd/domain.rb:100:inblock in relationships_mapping'
rails-erd (0.4.5) lib/rails_erd/domain.rb:99:in tap' rails-erd (0.4.5) lib/rails_erd/domain.rb:99:inrelationships_mapping'
rails-erd (0.4.5) lib/rails_erd/domain.rb:77:in relationships_by_entity_name' rails-erd (0.4.5) lib/rails_erd/domain/attribute.rb:58:inforeign_key?'
rails-erd (0.4.5) lib/rails_erd/domain/attribute.rb:40:in content?' rails-erd (0.4.5) lib/rails_erd/diagram.rb:178:inblock (2 levels) in filtered_attributes'
rails-erd (0.4.5) lib/rails_erd/diagram.rb:178:in each' rails-erd (0.4.5) lib/rails_erd/diagram.rb:178:innone?'
rails-erd (0.4.5) lib/rails_erd/diagram.rb:178:in block in filtered_attributes' rails-erd (0.4.5) lib/rails_erd/diagram.rb:175:inreject'
rails-erd (0.4.5) lib/rails_erd/diagram.rb:175:in filtered_attributes' rails-erd (0.4.5) lib/rails_erd/diagram.rb:129:inblock in generate'
rails-erd (0.4.5) lib/rails_erd/diagram.rb:128:in each' rails-erd (0.4.5) lib/rails_erd/diagram.rb:128:ingenerate'
rails-erd (0.4.5) lib/rails_erd/diagram.rb:119:in create' rails-erd (0.4.5) lib/rails_erd/diagram.rb:74:increate'
erd (0.1.1) app/controllers/erd/erd_controller.rb:14:in index' actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:insend_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in process_action' actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:inprocess_action'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in block in process_action' activesupport (3.2.3) lib/active_support/callbacks.rb:458:in_run__4443814287318799090__process_action__2694220428115231325__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.3) lib/active_support/callbacks.rb:385:in_run_process_action_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:inprocess_action'
actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in process_action' actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:inblock in process_action'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in block in instrument' activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:ininstrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in instrument' actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:inprocess_action'
actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in process_action' activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:inprocess_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:121:in process' actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:inprocess'
actionpack (3.2.3) lib/action_controller/metal.rb:203:in dispatch' actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:indispatch'
actionpack (3.2.3) lib/action_controller/metal.rb:246:in block in action' actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:incall'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in dispatch' actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:incall'
journey (1.0.3) lib/journey/router.rb:68:in block in call' journey (1.0.3) lib/journey/router.rb:56:ineach'
journey (1.0.3) lib/journey/router.rb:56:in call' actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:incall'
railties (3.2.3) lib/rails/engine.rb:479:in call' railties (3.2.3) lib/rails/railtie/configurable.rb:30:inmethod_missing'
journey (1.0.3) lib/journey/router.rb:68:in block in call' journey (1.0.3) lib/journey/router.rb:56:ineach'
journey (1.0.3) lib/journey/router.rb:56:in call' actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in call' rack (1.4.1) lib/rack/etag.rb:23:incall'
rack (1.4.1) lib/rack/conditionalget.rb:25:in call' actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in call' actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:incall'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in context' rack (1.4.1) lib/rack/session/abstract/id.rb:200:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in call' activerecord (3.2.3) lib/active_record/query_cache.rb:64:incall'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in call' actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in _run__4376859758047906647__call__2221242394031032558__callbacks' activesupport (3.2.3) lib/active_support/callbacks.rb:405:in__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in _run_call_callbacks' activesupport (3.2.3) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in call' actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in call' actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in call' railties (3.2.3) lib/rails/rack/logger.rb:26:incall_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in call' actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:incall'
rack (1.4.1) lib/rack/methodoverride.rb:21:in call' rack (1.4.1) lib/rack/runtime.rb:17:incall'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in call' rack (1.4.1) lib/rack/lock.rb:15:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in call' railties (3.2.3) lib/rails/engine.rb:479:incall'
railties (3.2.3) lib/rails/application.rb:220:in call' rack (1.4.1) lib/rack/content_length.rb:14:incall'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in call' rack (1.4.1) lib/rack/handler/webrick.rb:59:inservice'
/Users/aabolts/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service' /Users/aabolts/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:inrun'
/Users/aabolts/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Rails 5.2

class << self
       def status
         migrated_versions = ActiveRecord::Base.connection.select_values("SELECT version FROM #{ActiveRecord::Migrator.schema_migrations_table_name}").map {\|v\| '%.3d' % v}
         migrations = []
         ActiveRecord::Migrator.migrations_paths.each do \|path\|
           Dir.foreach(Rails.root.join(path)) do \|file\|
--

vendor/bundle/ruby/2.5.0/gems/erd-0.4.0/lib/erd/migrator.rb:9:in status' vendor/bundle/ruby/2.5.0/gems/erd-0.4.0/app/controllers/erd/erd_controller.rb:19:in index'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.