Jun 29 2010

Doctrine migrations

Posted by German Rumm in php, work

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.

  1. Get a “staging” server model files (checkout or copy)
  2. Put new schema.yml into config/doctrine directory replacing old one.
  3. and run
./symfony doctrine:generate-migrations-diff

Symfony 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.

Dec 15 2009

How to add empty directory to Git repo

Posted by German Rumm in work

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/.gitignore

Now, when you do git add, only .gitignore files will be added for those directories, and all other files will be ignored.

Apr 06 2009

Speed up symfony’s apps

Posted by German Rumm in php

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.