How to version control your data model

Data model can be a pain to maintain among a group of developers. Mostly at the beginning where the data model is very likely to change frequently due to new system requirements and specifications.

When using MySQL Workbench you get all those UI niceties. You can see how your tables interact with each other, table attributes “right there” and so on. The problem is, when you save your data model Workbench will save it as a binary file, a .mbw file type. Therefore, if you use your version control system, like git, it wont let you see the file changes from each commit.

You may say, let the UI niceties go down the hole and just do it by hand and make yourself your data model using SQL and use the resulting .sql file on your version control system. It’s one of those choices where you can only pick one. Either use the UI from Workbench, or any other data modelling software, for a fast and easy development but you lose the ability to check for data changes and have a rather slow process of commiting your changes (you would have to ask your team if anyone as also updated the data model so he wont lose his changes) or use a slow, tedious and non descriptive process of creating the data model by coding the SQL but get all the power the version control system provides you, like check file changes and, most importantly, manage merges and merge conflicts.

What if you could join both in one? Actually you can, at least with Workbench. It is easy as saving your data model as a .sql file (File -> Export -> Forward Engineer SQL CREATE Script) and use that .sql file as your data model on your version control system. When you want to load your .sql file as a graphical data model you just need to click on the right pointing arrow and select “Create EER Model From Script”, as shown below, select your .sql file that represents your data model and tick the “Place imported objects on a diagram” box. Workbench will load the file and display your data model like your were actually opening the .mwb file.


Now you have both worlds together, the niceties of your UI and the power of your version control system.