DEV Community

Collin
Collin

Posted on

Rails DB Schema Visualization

Looking at the schema.rb file inside a rails application is a great way to get a sense of the layout of the application. It's a nice one stop shop for finding out about the models and the attributes of those models that the application is modeled with, however sometimes it can still be a bit daunting to make sense of it all.

If only there was a way to see how everything was connected!

While there are schema design tools out there that allow you to write out the SQL to create and get a visual layout of the database schema, it requires you to write it all out by hand and more often than not it is in a slightly different syntax than actual SQL.

Remembering the syntax for languages is difficult enough, so why add yet another to the pile?

Just when it seems all hope is lost, a helping hand has come to the rescue!

dbdiagram has added in support for importing you rails schema and turning it into the required syntax for their program and thus printing out a beautiful representation of your applications database which can then be exported and shared with your team.

To make this happen simply visit dbdiagram, click the import button in the top of the window, select the import from Rails(schema.rb) option from the drop down:
dbdiagram window screenshot

This will open up a window in which the contents of the applications schema.rb file can be uploaded by clicking the upload schema.rb button in the top right of the window. You can then navigate to the location on your machine where the application lives and get to its schema.rb file and click open once you have the schema.rb selected. Once you click open you should see the contents of the applications schema file appear in dbdiagram's window:
dbdiagram window screenshot

Next, click the submit button at the bottom and then you will see the applications schema nicely laid out for you which can then be moved around the page by clicking and dragging the tables around to allow for even further readability:
dbdiagram window screenshot

Happy Rubying!

Discussion (0)