Using DBDesigner to generate Rails files

dbmodel is a tool to generate Rails files (models, scaffolds) from a free graphic database design tool, DBDesigner 4. You can create tables in DBDesigner, specify table relations, synchronize the model with a MySQL database, and then use dbmodel to automatically generate code. Table relationships like "has_many :beers" are inserted into the appropriate model files if they aren't already there. (dbmodel is non-destructive, hopefully.)

dbmodel version 0.1.0 is available as a gem. This is my first exercise in building a gem, or a Ruby tool for that matter, so suggestions are very welcome. The idea for dbmodel fell naturally out of the DRY principle. I'm releasing early in the hopes of sparking brainstorms on how to graft nice front-end tools to the very coder-friendly Rails framework. Then we'll have the best of both worlds: nice design tools and easy-to-read code when drilling down into programs.

I first used DBDesigner when designing the data model for the Writertopia prototype in PHP. It's a great piece of free software although development has been halted while the creators (acquired by MySQL) work on its successor, MySQL Workbench. In order to use DBDesigner's synchronize feature with MySQL 4.1+, you'll have to create an account with an old password format.

In these screenshots, the tables are segregated using colored regions corresponding to website features. I've sized each region to approximately one US letter page for easy printing of my model. Relations are added by simply clicking the source and destination tables. A Rails-compliant declaration is used as the name of the relation. If there are too many relationships within the field of view, you can make selected ones invisible. By default, DBDesigner saves data models in an XML format.

After installing the the dbmodel gem, save your DBDesigner XML file in your Rails app /db folder. The command dbmodel mymodel.xml will generate model files for all tables with relations. You can choose scaffolding by embedding tags within your table comments.

See the Ruby on Rails wiki page for dbmodel for more information.

Update 2/26/2006: dbmodel is not being actively developed at this point because DBDesigner is now a legacy application. MySQL is working on MySQL Workbench, which looks to be far more flexible and has built-in scripting language support (unfortunately, not Ruby). When Workbench reaches a usable form, I'll revisit the dbmodel concept and integrate support for migrations, which didn't exist when I wrote the first version of dbmodel.

July 25, 2005 – 18:41

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Won't work

Installed as documented. Command >ruby script/generate dbmodel with dbmodel.xml in db folder (as documented) results in "Couldn't find 'dbmodel' generator" error.

I'm using windows xp.

Steve (not verified) – June 16, 2006 – 13:29

Great tool!

Thanks for sharing this tool.

ctran (not verified) – August 2, 2005 – 00:21