Yii Framework Forum: Improve migrations support - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Improve migrations support

#21 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 10 July 2012 - 02:22 AM

View Postsensorario, on 03 July 2012 - 11:49 PM, said:


I can traslate model to db and db to model. I think is great!!! I can auto-generate migrations.

A client of mine has started a job without migrations. He has a lot of tables. I need to create schema with migration now. But I cant.

Maybe with DumpSchemaCommand I'll can. Thank you @schmunk


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".
0

#22 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 10 July 2012 - 04:09 AM

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);
     	} 

"Less noise - more signal"
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users