Before stepping into the Railsconf 2012 lightning talks, the last time I saw a database schema visualizer was when Microsoft Access 97 was cool. Okay, that time may never have existed, but I can verify that I personally haven't run into too many visualizers since those days. Enter the fine cookpad engineers who came all the way from the Land of the Rising Sun for Railsconf festivities, including the lighting presentation of a fun gem called erd. It gives you a graphic birds-eye-view of your schema and it's pretty easy to use:
gem install erd
Then start rails server and look for the magic at localhost:3000/erd
If you get the following error:
Saving diagram failed!
Verify that Graphviz is installed and in your path, or use filetype=dot.
You'll want to download and install Graphviz
(hombrew users can 'brew install graphviz')
I find erd handy when trying to understand a new project quickly. Let's say I want to see how a simple blog application, enki, thinks about its data.
After following the install instructions and installing the erd gem*, we see the fruits of our labors:
Not bad. Gives a nice overview of the schema and jumping off point for understanding a new project. It even has (fledgling) support for editing the schema and generating rails migrations.
Which Access 97 feature shall we port to rails next?
* I also needed to comment out a clashing route:
scope :to => 'posts#index' do
get 'posts.:format', :as => :formatted_posts
#get '(:tag)', :as => :posts
Photo Credit: John Parker