Automatic migrations in Yii after git pull
August 1, 2012
I have been using Git and Yii Framework for a long time. I develop projects mostly in a team. So I have to use the migrations (changes in the database's structure). I am interested in how I can automate the usage of automatic migrations.
It is possible to use Git Hooks in Git which allow you to perform any additional actions (scripts) before or after some operations. I want to execute Yii Migrations each time when I update from repo and when there is a probability to change the database structure from my colleagues.
Every time when I do git pull I should run the script that performs the applying of new Yii migrations. If you want to do this just create the file .git/hooks/post-merge with simple bash script:
#!/bin/sh cd /var/www/yiiproject/protected/ php yiic.php migrate --interactive=0
cd /var/www/yiiproject/protected/ - go to the directory with the project
php yiic.php migrate --interactive=0 - perform the migration, with the parameter --interactive=0, which allows you to automatically perform the migration without using a confirmation from the user.
Now whenever you update git pull should run this script, which must comply with existing migration.