DEV Community

Collin
Collin

Posted on

11 1

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!

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (1)

Collapse
 
bhupendra9211 profile image
Bhupendra Shah

if migration file contains comments init and i want to view that comment section into dbdiagram. for this what to do??

Neon image

Set up a Neon project in seconds and connect from a Ruby application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay