Tuesday, June 14, 2011

Generate rails from a ERD ?

This isn't much of a blog post, it's a question !  I love ERDs (Entity Relationship Diagrams)  for database design and have been known to produce them before the database or the code .  Recently I've been doing a lot of work in Ruby on Rails which generates the database and model code for you, hiding the database under a ORM layer.  This is all very well and good  but you can see my problem.  No longer can I build  a ERD, check it's normalisation  nd optimise it with a bit of de-normalisation.

So, the question is:

Is there a tool out there that will take a ERD and generate the rails commands to build a app from the ERD.  I mean create the models and generate the migrations at least  ?

Suppose you had an ERD like this:

When I want to generate rails this would do something like the following

rails generate scaffold Person name:string
rails generate scaffold Town name:string<
rake db:migrate

It would then go in and alter the model for Person to set up the relationship to town.

Answers on a postcard !


  1. I've been wondering this for a while too... they have reverse ones that will build the erd from schema.rb. I prefer building the ERD before the app so I can think about how the data will flow. But I can't seem to find a tool to do this.

  2. looks like I found something... it will generate a rails migration from an erd... http://www.malcolmhardie.com/sqleditor/ If you go to file and save you can pick 'rails' as an option

  3. Hi Will, thats a handy tool, but ! I'd like it to generate the models as well so as to catch the releationships (such as belongs_to and has_one etc). Hmmm

  4. I am really not sure about any tool for this so far. We generally do it manually on papers. I love ERDs too, but it usually a big mesh to handle. Thanks to Will for the help. This will help us from now.

    SEO Philadelphia

  5. Hey nice post. Thanks for sharing this great post with us. It is truly very interesting post.
    Magento Development

  6. Really this is very good blog thanks for the time you took in writing this post.I would like to come on this blog again and again.
    Hire website developers

  7. This comment has been removed by the author.

  8. hmm this site is really cool and full of informative stuff.

    Application Developer Facebook

  9. Wow really your post was very nice..explain the real practices as very clear...Thank you..
    Web Design

  10. i Actually dont no much about ERD tool.We work on Ruby on Rails

    If we would help you in any way Contact Us @ http://www.rizecorp.com

    Ruby on Rails | Ruby on Rails Development | Rails Development

  11. Wonderful information. I will go to share this to my friends...

    ROR Development | Ruby on Rails Development

  12. It is nice blog Thank you porovide importent information and i am searching for same information to save my timeRuby on Rails Online Training Hyderabad

  13. This is really very good article..i would to like to read your article again n again.thanks for sharing with us.

  14. Thank you so much for sharing this wonderful post! This article is very helpful for a website developer.

  15. Really this is very good blog thanks for the time you took in writing this post.I would like to come on this blog again and again.

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai