Develop Simply

Ivan K's development musings

Timestamped Migrations

All non-trivial web projects that use RDBMS need some sort of database migration system to manage database changes and schema evolution. But the tools for that for Kohana 3 are of course … you got it - lacking. There is Kohana-3-migraitons - but versioned migrations work only for a single developer - if that’s your situation - I envy you, I really do - so much less headache. But when you try to collaborate database changes, especially with git/svn managing your files - you soon start to say very inappropriate words, very very loudly. So I went on and rewrote null77’s excellent module kohana-migrations for Kohana 3 - Timestamped Migrations, but with some more sugar.

1
git clone git://github.com/OpenBuildings/timestamped-migrations.git modules/timestamped-migrations

Or

1
2
git submodule git://github.com/OpenBuildings/timestamped-migrations.git modules/timestamped-migrations
git submodule update --init

So now your migrations will look like

1
2
1319717756_initial.php
1319717856_migrate_users_and_roles.php

Might seem a bit too verbose, but it’s a godsend when you have more than one person on a project - you can just drop a migration file and have it execute in just the right place and order - delightfully convenient.

I personally detest web interfaces for those kind of tasks - exposing system tools to a webserver seem … unclean, so I’ve ditched the controllers and views, and implemented simple CLI for this, using Kohana-cli and mimicking rails’ syntax as much as possible. Check it out.

1
2
3
4
5
6
kohana db:version
kohana db:migrate
kohana db:migrate:up
kohana db:migrate:down --step=4
kohana db:migrate:redo --version=1319717756
kohana db:rollback

You can read all about it at the github README file. Enjoy.