Feb
06
2009
5

mwbModelCommand, Yii Framework and MySQL Workbench

In the past few weeks we have been exploring with Yii Framework, and two of us have started porting some of our project to Yii Framework. One of the first few things that caught our attention is the CActiveRecord model classes, which require relational rules to describe relationships among database tables. We are glad that Yiic can help to create project scaffolds and create controller, model and CRUD, however it's not very practical to manually add all the relationship if your project has over 10 tables.

Our normal practice prefers to design database with relational diagram, so it not only sets out the table schemas but also visually demonstrates the relationship of database tables. However in this fast changing world, without the right tool most the relational diagram tends to out of sync with real production database. For most the of our project, we create ERD and generate database from the diagram in the design phase and later on in the development phase, most the developer choose to update the schema on the table directly, since that's quick, and most of them don't have the habit to update the ERD with relavant changes. You will feel lucky if your database design tool comes with reverse engineering, which can help you syn with your database at a later point still, otherwise you'll be purely rely on your bare eye and hand to syn among database table your model classes and the ERD.

So I believe when it comes to database design it should always be diagram driven, therefore if there's any changes need to be made, always update the digram first and carry on to your physical table and model class. Although we are still looking for good database migration tools to manage schema diffs. We have written a little script to help Yii Framework to work with MySQL Workbench (which we use to model MySQL databases), the purpose of the script is to batch create model classes for Yii Framework (although Yiic can generate models one by one, we want it happen at once and for all), and with the help of mwb file it can create the relational rules for the models, so there's no manual translation needed while you creating the models. Since it's a Yii shell command, we have named it 'mwbModelCommand'.

It's available for download at this Yii Extensions page, or Yii Framework mwbModelCommand (direct link)

Hope this script will save your time on relational model creation, if anyone have issues or suggestions mwbModelCommand please feel free to post back.

Wish List (Todo),
A tool (set) to stream line the database migration, so it would not only creates the models, but may also update (revert) models as well as database table schema at once, and data safe if possible. Please advice if you know something good out there.

Copyright Orite Group Pty Ltd | Powered by WordPress | Theme: Aeros 2.0