Finally learned how to use Doctrine migrations.
You have development and staging servers. Your development server moved forward – you did some database changes, removed some fields, added some indexes. Now it’s tricky to update staging server without rebuilding the db (and losing all the data).
Sure, you can alter database by hand, but if you made a lot of changes, that would be a long and error-prone process.
That’s when you are supposed to use migrations.
There was only one problem – I didn’t know how to use them correctly. Now I figured it out.
./symfony doctrine:generate-migrations-diffSymfony will now generate a migration file that brings your database up to date.
Now, when you deploy your changes just run
./symfony doctrine:migrate
Now I just have to remember doing generate-migrations-diff before every doctrine:build –all, so I will have all the necessary files before uploading.
I keep all my Symfony projects in a Git repositories. Makes my life a lot easier – I can upload only changed files on update, which makes updating faster and more reliable.
But, apart from the code files logs and cache files are always changing, and I don’t really need and want to keep them in repo. I used .gitignore to filter out log and cache directories, but everytime I “checkout” repo I need to create them by hand. What I needed is to “git add” directories but ignore directory contents.
The problem is that if you ignore directory contents, directory appears empty to Git, and Git ignores empty directories automatically, so
cache/*
prevents me from adding cache directory at all.
Finally I found a solution to my problem in the Git Cheat Sheet at GitHub. http://github.com/guides/git-cheat-sheet
First, in root .gitignore file you ignore all the directories as usual, and add an exception for the .gitignore file
log/* cache/* !.gitignore
And then just add empty .gitignore files into log/ and cache/ firectories.
$ touch log/.gitignore cache/.gitignoreNow, when you do git add, only .gitignore files will be added for those directories, and all other files will be ignored.
Kris Wallsmith submitted a patch to symfony, that supposed to increase the speed of your apps, especially if you are using cache.
Currently it’s only available from SVN (or as a patch)
Hope Fabian will release 1.2.6 soon, my server’s admin doesn’t like to install unstable libs.