Improve migrations support

I think there is no need to reproduce an existing database in migrations - too much work without any benefit.

Migrations are great when they are connected to a code changes - you can checkout an older source version and get an appropriate DB state.

And I had the same situation - our current project was started without migrations and then we switched to db changes via migrations. Here even if we re-build db structure with migrations it will be still the same signle state, because you can not put migrations into previous appropriate commits with code changes.

Our solution is this: we have one solid SQL script "init.sql" (initial database state before migrations) and migrations applied on top of it.

This initial "init.sql" script can be created using console command like schmunk suggested or using mysqldump util or via phpmyadmin (actually any tool which can dump a database into a script).

To re-create a current database (for example, on test server) we use a shell script which creates database, loads "init.sql" and then run migrations.

To upgrade an existing database to the latest version we just run "yiic migrate up".

What I did - before converting it to proper migration code - was this:


class m110508_200344_initial_data extends CDbMigration {

 	public function safeUp()

 	{

         	$sql = "";

         	$fd = fopen(dirname(__FILE__).'/../data/data.sql', "r");

         	if($fd) {

             	while (!feof($fd)) {

                 	$sql .= fread($fd, 1024);

             	}

             	fclose($fd);

         	}

         	$this->execute($sql);

     	}