Shane Dowling : SugarCRM — Versioning Your Database

One issue that constantly re-occurs for me using SugarCRM is that certain knowledge is only stored in it's database. So say you want to revert to a previous version of Sugar and wish to obtain the Studio customisations you've done at that version, say two days ago, well your just out of luck. This is pretty annoying considering most of your day to day changes will probably be in Studio and you have no real way to see those changes outside of Sugar's "View History", which leaves a lot to be desired mostly as again, it's all in the DB. You're effectively left to sharing a database dump between developers.

What I've done on my development environment is created a simple pre-commit git-hook(good explanation of those here) that essentially commits the database structure and the fields_meta_data table. This essentially means someone can get themselves up and running with a basic variant of my install pretty quickly including my studio changes, which are now all tracked in version control too. So put code resembling the below in your .git/hooks/pre-commit

rm /database/sugar.sql
 mysqldump -u root -p  no-data > /database/sugar.sql
 mysqldump -v -u root -p fields_meta_data >> /database/sugar.sql

Originally I had this creating a gzipped time-stamped version of sugar database dumps, but considering the SQL is small it makes much more sense to leverage the plain-text advantages git gives you, and simply track the changes through git rather than timestamped DB dumps.

Note: I only use this script on my local dev environment. This also isn't version controlled either, so I don't mind that my dev database password is stored in plaintext.