[extension] Yii DB Migrations - very early alpha release

Hi all,

I've started working on an extension that can do database migrations for a Yii project. It's kind of inspired by what is possible in Ruby On Rails.

Currently, the basics are working for SQLite and MySQL. There is still a lot of work that needs to be done to make this a full working tool though.

You can have a look at what I've come up with so far on:

http://github.com/pi…i-dbmigrations/

Regards,

pieter

Hi Pieter,

That is an awesome piece of work! Documentation is top notch too.

++karma!

Cheers, Wei.

great

I hope that we can specify a different CDbConnection

You actually can specify a different connection in some way. Since the migrate command is part of the yiic tool, it looks at the settings defined in the "protected/config/console.php" configuration file while the webapp normally looks in the "protected/config/main.php" configuration file.

This way, you can have a db connectionstring for migrate that has a lot more rights than what the one you are using in the web application itself has.

regards,

pieter

WoW, nice piece of code :)

Will be there a "reverse" migration of existing tables?

Yes, currently, you can only migrate in the "up" direction, but the goal is that you can migrate in the "down" direction as well.

Eventually, I would like to come up with the following possibilities in the migrate command:

  • yiic migrate: applies all possible migrations
  • yiic migrate 20091116111958: migrate to that specific version
  • yiic migrate down: undo the last migration

That way, you can go any direction.

Regards,

pieter

Quote

You actually can specify a different connection in some way. Since the migrate command is part of the yiic tool, it looks at the settings defined in the "protected/config/console.php" configuration file while the webapp normally looks in the "protected/config/main.php" configuration file.

This way, you can have a db connectionstring for migrate that has a lot more rights than what the one you are using in the web application itself has.

regards,

pieter

thanks pieter

And whats about creation of migrations with existing tables? :)

There are functions provided to add/edit things in existing tables.

I currently have no plans to automatically create migrations from an existing database though.

pieter

I've just made version 1.0a1 available of the Yii DB Migrations extension.

The following changes were made since the initial announcement:

  • The migrations are now performed inside a database transaction
  • Big code cleanup by adding all needed docstrings
  • When renaming a column, the data type is retained
  • You can now migrate up, down or to a specific version
  • You can now list the status of all migrations

Downloads are available on:

http://github.com/pi…i-dbmigrations/

The extension is also available in the Yii extensions directory under:

http://www.yiiframew…i-dbmigrations/

Cheers,

pieter

Hi ,

I would like to try the extension , i have followed the steps until Configuring the command map and I am not too sure where I should put this to …

'commandMap' => array(


    'migrate' => array(


        'class'=>'application.extensions.yii-dbmigrations.CDbMigrationCommand',


    ),


),

And I have tried put to config/main.php it is not working. Pls advice. Thanks.

You need to put this in the "protected/config/console.php" file.

cheers,

pieter

Hi Pieter ,

Thanks , follow your instruction I got it working but seems that it calls only yiic.bat from within the application not the yii/framework/yiic.bat , if i call shell using yii/framework it is not working , so is it possible to get the yii-dbmigration to put into the yii/framework as all applications develop should use the same yii-dbmigration extension. ?

Thanks.

Hi kalmenchia,

as far as I know, there is no way (yet?) to install an extension sytem-wide without altering your install of the framework.

Cheers,

pieter

I think people are using symlinks to reduce redundancy in filesystem for multiple apps.

Wow, work like rails, but I have one question:

How can I generate automatic blank migration files?

To simplify the naming of files.

Thanks.

If you download the latest version from github, you will see that I added a new command that creates a blank migration:


protected yiic migrate create MyTestMigration

That will create the timestamped file with an empty migration in there.

Regards,

pieter

Hi,

i have a little feature request:

I would like to configure more databases for

one project e.g production, testing, development

and therefore i need the opportunity to migrate

to given version and given environment e.g.

yiic migrate env=testing for migrating the testing database

Thanks for sharing your great work!

Greetings from Germany

me23

Actually I’m using a older version of this extension.

How can I update this extencion in my aplications? Just overwrite the classes in extensio directory?

Thanks.