[extension] Yii DB Migrations - very early alpha release


(Pieter) #1

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


(Weizhuo) #2

Hi Pieter,

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

++karma!

Cheers, Wei.


(Cuiming2355 Cn) #3

great


(Cuiming2355 Cn) #4

I hope that we can specify a different CDbConnection


(Pieter) #5

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


(Tesion) #6

WoW, nice piece of code :)

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


(Pieter) #7

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


(Cuiming2355 Cn) #8

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


(Tesion) #9

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


(Pieter) #10

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


(Pieter) #11

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


(Kalmenchia) #12

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.


(Pieter) #13

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

cheers,

pieter


(Kalmenchia) #14

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.


(Pieter) #15

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


(Yii) #16

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


(Santiago Carmo) #17

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

How can I generate automatic blank migration files?

To simplify the naming of files.

Thanks.


(Pieter) #18

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


(Yii) #19

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


(Santiago Carmo) #20

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.