[extension] Yii DB Migrations - very early alpha release

I’m doing something like that in my own applications. In the index.php and yiic.php scripts, I’ve added a check to see if I’m in the development or production environment. Based on that, I’m setting the YII_DEBUG constant.

Additionally, in the config files, I’m checking if YII_DEBUG is true or not and include the correct database configuration file.

Depending on how you distinguish the development from the production system, you will need a different kind of check.

For me, the rule is:

  • For index.php: if the server name is localhost, I’m in the development environment

  • For yiic.php: I’m checking for the existance of an environment variable that indicates the enviroment

Cheers,

pieter

Yes, you can just replace the entire yii-dbmigrations directory with the new version.

Regards,

pieter

Note: If you are on in windows, and from germany, you have to set the right timezone :)

Suggestion: Why not change those "hundred" array`s to something like this:




public function up

{

    $this->createTable(

        'tablename: field1 :: type1,

                    field2 :: type2,

                    field3 :: type3'

    )


}



Speed shouldn’t have a big impact, and would look much cleaner :)

I will see what I can do for version 2.0 to make it less verbose.

pieter

Hello Pieter,

I am getting the following error message after running "protected/yiic migrate -create mymigration":

ERROR: Invalid migration: -create

It seems the "create" option is not implemented or I am using a wrong version.

Thanks,

Ramin

You’ve made an error in the command. You should use the following (without the dash in front of the create command):


protected/yiic migrate create mymigration

Cheers,

pieter

The dash was a typo when I replied to your post. This is what I’ve got:

ramin$ protected/yiic migrate create mymigration

ERROR: Invalid migration: create

ramin$

Thanks,

Ramin

The ‘timestamp’ type mapping creates ‘datetime’ type.

Regards,

Ramin

Hi guys,

I’m having some problens when I try to create new migrations.

I created a new application using version 1.0.10 of yii, and when I try create a new migration, the console show this error:


Migrations directory: protected/migrations/


Creating initial schema_version table

PHP Error[2]: PDOStatement::execute() expects parameter 1 to be array, string given

in file /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php at line 352

#0  CConsoleApplication->displayError(2, PDOStatement::execute() expects parameter 1 to be array, string given, /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php, 352) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/base/CErrorHandler.php:204]

#1  CErrorHandler->handleError(CErrorEvent Object ([code] => 2,[message] => PDOStatement::execute() expects parameter 1 to be array, string given,[file] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php,[line] => 352,[sender] => CConsoleApplication Object ([commandMap] => Array ([migrate] => Array ([class] => application.extensions.yii-dbmigrations.CDbMigrationCommand)),[] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/commands,[] => CConsoleCommandRunner Object ([commands] => Array ([migrate] => Array ([class] => application.extensions.yii-dbmigrations.CDbMigrationCommand),[message] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/cli/commands/MessageCommand.php,[shell] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/cli/commands/ShellCommand.php,[webapp] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/cli/commands/WebAppCommand.php),[] => ./protected/yiic,[] => ,[] => ),[name] => My Console Application,[charset] => UTF-8,[sourceLanguage] => en_us,[] => ,[] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected,[] => ,[] => ,[] => ,[] => ,[] => ,[] => ,[preload] => Array (),[behaviors] => Array (),[] => ,[] => ,[] => ,[] => ,[] => ,[] => Array (),[] => Array (),[] => Array ([db] => CDbConnection Object ([connectionString] => mysql:host=localhost;dbname=nagloria;unix_socket=/tmp/mysql.sock,[username] => root,[password] => ,[schemaCachingDuration] => 0,[schemaCachingExclude] => Array (),[schemaCacheID] => cache,[autoConnect] => 1,[charset] => ,[emulatePrepare] => 1,[enableParamLogging] => ,[enableProfiling] => ,[] => Array (),[] => 1,[] => PDO Object (),[] => ,[] => CMysqlSchema Object ([] => ,[] => ,[] => Array (),[] => Array ([schema_version] => ),[] => CDbConnection Object ( *RECURSION*,[] => ,[] => Array (),[] => ,[] => ),[behaviors] => Array (),[] => 1,[] => ,[] => ),[coreMessages] => CPhpMessageSource Object ([cachingDuration] => 0,[cacheID] => cache,[basePath] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/messages,[] => Array (),[] => en_us,[] => Array (),[behaviors] => Array (),[] => 1,[] => ,[] => ),[errorHandler] => CErrorHandler Object ([maxSourceLines] => 25,[adminInfo] => the webmaster,[discardOutput] => 1,[errorAction] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => )),[] => Array ([messages] => Array ([class] => CPhpMessageSource),[securityManager] => Array ([class] => CSecurityManager),[statePersister] => Array ([class] => CStatePersister),[urlManager] => Array ([class] => CUrlManager),[request] => Array ([class] => CHttpRequest)),[] => ,[] => ),[handled] => 1,[] => ,[] => )) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/base/CErrorHandler.php:96]

#2  CErrorHandler->handle(CErrorEvent Object ([code] => 2,[message] => PDOStatement::execute() expects parameter 1 to be array, string given,[file] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php,[line] => 352,[sender] => CConsoleApplication Object ([commandMap] => Array ([migrate] => Array ([class] => application.extensions.yii-dbmigrations.CDbMigrationCommand)),[] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/commands,[] => CConsoleCommandRunner Object ([commands] => Array ([migrate] => Array ([class] => application.extensions.yii-dbmigrations.CDbMigrationCommand),[message] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/cli/commands/MessageCommand.php,[shell] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/cli/commands/ShellCommand.php,[webapp] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/cli/commands/WebAppCommand.php),[] => ./protected/yiic,[] => ,[] => ),[name] => My Console Application,[charset] => UTF-8,[sourceLanguage] => en_us,[] => ,[] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected,[] => ,[] => ,[] => ,[] => ,[] => ,[] => ,[preload] => Array (),[behaviors] => Array (),[] => ,[] => ,[] => ,[] => ,[] => ,[] => Array (),[] => Array (),[] => Array ([db] => CDbConnection Object ([connectionString] => mysql:host=localhost;dbname=nagloria;unix_socket=/tmp/mysql.sock,[username] => root,[password] => ,[schemaCachingDuration] => 0,[schemaCachingExclude] => Array (),[schemaCacheID] => cache,[autoConnect] => 1,[charset] => ,[emulatePrepare] => 1,[enableParamLogging] => ,[enableProfiling] => ,[] => Array (),[] => 1,[] => PDO Object (),[] => ,[] => CMysqlSchema Object ([] => ,[] => ,[] => Array (),[] => Array ([schema_version] => ),[] => CDbConnection Object ( *RECURSION*,[] => ,[] => Array (),[] => ,[] => ),[behaviors] => Array (),[] => 1,[] => ,[] => ),[coreMessages] => CPhpMessageSource Object ([cachingDuration] => 0,[cacheID] => cache,[basePath] => /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/messages,[] => Array (),[] => en_us,[] => Array (),[behaviors] => Array (),[] => 1,[] => ,[] => ),[errorHandler] => CErrorHandler Object ([maxSourceLines] => 25,[adminInfo] => the webmaster,[discardOutput] => 1,[errorAction] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => )),[] => Array ([messages] => Array ([class] => CPhpMessageSource),[securityManager] => Array ([class] => CSecurityManager),[statePersister] => Array ([class] => CStatePersister),[urlManager] => Array ([class] => CUrlManager),[request] => Array ([class] => CHttpRequest)),[] => ,[] => ),[handled] => 1,[] => ,[] => )) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/base/CApplication.php:630]

#3  CApplication->handleError(2, PDOStatement::execute() expects parameter 1 to be array, string given, /Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php, 352, Array ([this] => CDbCommand Object ([] => CDbConnection Object ([connectionString] => mysql:host=localhost;dbname=nagloria;unix_socket=/tmp/mysql.sock,[username] => root,[password] => ,[schemaCachingDuration] => 0,[schemaCachingExclude] => Array (),[schemaCacheID] => cache,[autoConnect] => 1,[charset] => ,[emulatePrepare] => 1,[enableParamLogging] => ,[enableProfiling] => ,[] => Array (),[] => 1,[] => PDO Object (),[] => ,[] => CMysqlSchema Object ([] => ,[] => ,[] => Array (),[] => Array ([schema_version] => ),[] => CDbConnection Object ( *RECURSION*,[] => ,[] => Array (),[] => ,[] => ),[behaviors] => Array (),[] => 1,[] => ,[] => ),[] => SELECT `id` FROM `schema_version` ORDER BY `id`,[] => PDOStatement Object ([queryString] => SELECT `id` FROM `schema_version` ORDER BY `id`),[] => Array (),[] => ,[] => ),[method] => fetchAll,[mode] => 7,[params] => id,[par] => ))

#4  PDOStatement->execute(id) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php:352]

#5  CDbCommand->queryInternal(fetchAll, 7, id) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/db/CDbCommand.php:321]

#6  CDbCommand->queryColumn(id) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/extensions/yii-dbmigrations/CDbMigrationEngine.php:187]

#7  CDbMigrationEngine->getAppliedMigrations() called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/extensions/yii-dbmigrations/CDbMigrationEngine.php:295]

#8  CDbMigrationEngine->applyMigrations(create) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/extensions/yii-dbmigrations/CDbMigrationEngine.php:86]

#9  CDbMigrationEngine->run(Array ([0] => create,[1] => users)) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/extensions/yii-dbmigrations/CDbMigrationCommand.php:99]

#10 CDbMigrationCommand->run(Array ([0] => create,[1] => users)) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/console/CConsoleCommandRunner.php:62]

#11 CConsoleCommandRunner->run(Array ([0] => ./protected/yiic,[1] => migrate,[2] => create,[3] => users)) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/console/CConsoleApplication.php:88]

#12 CConsoleApplication->processRequest() called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/base/CApplication.php:135]

#13 CApplication->run() called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/yiic.php:31]

#14 require_once(/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/yii/yiic.php) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/yiic.php:7]

#15 require_once(/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/yiic.php) called at [/Volumes/MAFIOUS/14bits/src/nagloria/trunk/web/public/protected/yiic:4]



I 'm calling this line on command line:


$ ./protected/yiic migrate create users 

And the configuration is that:




'commandMap' => array('migrate' => array('class' => 'application.extensions.yii-dbmigrations.CDbMigrationCommand')),


'components' => array('db' => array('class' => 'system.db.CDbConnection', 

              		      'connectionString' => 'mysql:host=localhost;dbname=nagloria;unix_socket=/tmp/mysql.sock', 

              		      'username' => 'root', 

              		      'password' => '',

              		      'emulatePrepare' => true)),

	



I did some tests with version 1.0.8 of yii and the extansion run well, but with 1.0.10 the problem happened.

Could you help me to fix up this?

Thanks.

Please download the latest version from github. It has this problem fixed.

Regards,

pieter

Hi,

actualy, I needed to do a downgrade to 1.0.8 version of yii, becouse I need to finish this job asap, but I have a new project to start on few days and I intent to test the last version of yii with yii-dbmigrations.

Thanks for your help.

To clarify, the downgrade was necessary to use dbmigrations, becouse I knew that dbmigration work on this version.

Thanks.

Hello!

Have the same error like GodFather:




PHP Error[2]: PDOStatement::execute() expects parameter 1 to be array, string gi

ven

in file Z:\home\vc\framework\db\CDbCommand.php at line 355

#0  CConsoleApplication->displayError(2, PDOStatement::execute() expects paramet

er 1 to be array, string given, Z:\home\vc\framework\db\CDbCommand.php, 355) cal

led at [Z:\home\vc\framework\base\CErrorHandler.php:204]

#1  CErrorHandler->handleError(CErrorEvent Object ([code] => 2,[message] => PDOS

tatement::execute() expects parameter 1 to be array, string given,[file] => Z:\h

ome\vc\framework\db\CDbCommand.php,[line] => 355,[sender] => CConsoleApplication

 Object ([commandMap] => Array ([migrate] => Array ([class] => application.exten

sions.yii-dbmigrations.CDbMigrationCommand)),[] => Z:\home\vc\preview\protected\

commands,[] => CConsoleCommandRunner Object ([commands] => Array ([migrate] => A

rray ([class] => application.extensions.yii-dbmigrations.CDbMigrationCommand),[m

essage] => Z:\home\vc\framework/cli/commands\MessageCommand.php,[shell] => Z:\ho

me\vc\framework/cli/commands\ShellCommand.php,[webapp] => Z:\home\vc\framework/c

li/commands\WebAppCommand.php),[] => Z:\home\vc\preview\protected\yiic.php,[] =>

 ,[] => ),[name] => My Console Application,[charset] => UTF-8,[sourceLanguage] =

> en_us,[] => ,[] => Z:\home\vc\preview\protected,[] => ,[] => ,[] => ,[] => ,[]

 => ,[] => ,[preload] => Array (),[behaviors] => Array (),[] => ,[] => ,[] => ,[

] => ,[] => ,[] => Array (),[] => Array (),[] => Array ([db] => CDbConnection Ob

ject ([connectionString] => mysql:host=localhost;dbname=vampirecastle,[username]

 => root,[password] => ,[schemaCachingDuration] => 0,[schemaCachingExclude] => A

rray (),[schemaCacheID] => cache,[autoConnect] => 1,[charset] => ,[emulatePrepar

e] => ,[enableParamLogging] => ,[enableProfiling] => ,[tablePrefix] => ,[] => Ar

ray (),[] => 1,[] => PDO Object (),[] => ,[] => CMysqlSchema Object ([] => ,[] =

> ,[] => Array (),[] => Array ([schema_version] => CMysqlTableSchema Object ([sc

hemaName] => ,[name] => schema_version,[rawName] => `schema_version`,[primaryKey

] => ,[sequenceName] => ,[foreignKeys] => Array (),[columns] => Array ([id] => C

MysqlColumnSchema Object ([name] => id,[rawName] => `id`,[allowNull] => 1,[dbTyp

e] => varchar(255),[type] => string,[defaultValue] => ,[size] => 255,[precision]

 => 255,[scale] => ,[isPrimaryKey] => ,[isForeignKey] => ,[] => ,[] => )),[] =>

,[] => )),[] => CDbConnection Object ( *RECURSION*,[] => ,[] => Array (),[] => ,

[] => ),[behaviors] => Array (),[] => 1,[] => ,[] => ),[errorHandler] => CErrorH

andler Object ([maxSourceLines] => 25,[adminInfo] => the webmaster,[discardOutpu

t] => 1,[errorAction] => ,[] => ,[behaviors] => Array (),[] => 1,[] => ,[] => ))

,[] => Array ([coreMessages] => Array ([class] => CPhpMessageSource,[language] =

> en_us,[basePath] => Z:\home\vc\framework\messages),[messages] => Array ([class

] => CPhpMessageSource),[securityManager] => Array ([class] => CSecurityManager)

,[statePersister] => Array ([class] => CStatePersister),[urlManager] => Array ([

class] => CUrlManager),[request] => Array ([class] => CHttpRequest)),[] => ,[] =

> ),[handled] => 1,[] => ,[] => )) called at [Z:\home\vc\framework\base\CErrorHa

ndler.php:96]






#4  PDOStatement->execute(id) called at [Z:\home\vc\framework\db\CDbCommand.php:

355]

#5  CDbCommand->queryInternal(fetchAll, 7, id) called at [Z:\home\vc\framework\d

b\CDbCommand.php:324]

#6  CDbCommand->queryColumn(id) called at [Z:\home\vc\preview\protected\extensio

ns\yii-dbmigrations\CDbMigrationEngine.php:162]

#7  CDbMigrationEngine->getAppliedMigrations() called at [Z:\home\vc\preview\pro

tected\extensions\yii-dbmigrations\CDbMigrationEngine.php:277]

#8  CDbMigrationEngine->applyMigrations(create) called at [Z:\home\vc\preview\pr

otected\extensions\yii-dbmigrations\CDbMigrationEngine.php:73]

#9  CDbMigrationEngine->run(Array ([0] => create,[1] => UserMigration)) called a

t [Z:\home\vc\preview\protected\extensions\yii-dbmigrations\CDbMigrationCommand.

php:39]

#10 CDbMigrationCommand->run(Array ([0] => create,[1] => UserMigration)) called

at [Z:\home\vc\framework\console\CConsoleCommandRunner.php:62]

#11 CConsoleCommandRunner->run(Array ([0] => Z:\home\vc\preview\protected\yiic.p

hp,[1] => migrate,[2] => create,[3] => UserMigration)) called at [Z:\home\vc\fra

mework\console\CConsoleApplication.php:88]

#12 CConsoleApplication->processRequest() called at [Z:\home\vc\framework\base\C

Application.php:135]

#13 CApplication->run() called at [Z:\home\vc\framework\yiic.php:31]

#14 require_once(Z:\home\vc\framework\yiic.php) called at [Z:\home\vc\preview\pr

otected\yiic.php:7]

I tried to use Yii 1.1beta is there any chance to continue without downgrading?

Please, specify the last supported version

Thank you!

Oh! I’ve just downloaded version from

http://www.yiiframework.com/extension/yii-dbmigrations/

not GitHub and it perfectly works!

Thank you for such a great extension!

DB connection works well for application.

but yii-dbmigrations (current git version) has a problem @ my install:

why app config is not acceptable by dbmigrations?

Hi,

I had the same problem and fix putting this on connection string

unix_socket=/tmp/mysql.sock

Hi,

I’m using the lastest version of yii-dbmigrations, and I saw that the form of create tables changed (from arrays to objects), and I can’t declare a field like int(11), so I’d like know:

How can I pass my own arguments to table fields?

Thanks

Hello,

I have the exact same problem, but I’m using SQLite (so the socket thing wouldn’t work)

thx,

–iM

never mind, I should learn to read the documentation first … ()forgot to setup the connection to the DB itself),

so it works so far :)

thx,

–iM

Hi folks,

I have a new problem using the latest version of yii-dbmigration, when I run the migration the console shows the message below and the migration not work




$ ./protected/yiic migrate

Migrations directory: protected/migrations/


=== Applying: m20110123200901_create_eav_table =================================

ERROR: m20110123200901_create_eav_table does not have a method named "performTransactional".




The code of migration is:




<?php


class m20110123200901_create_eav_table extends CDbMigration {

    

    public function up() {

      $t = $this->newTable('eav');

      $t->primary_key('id');

      $t->integer('section_id');

      $t->integer('entry_id');

      $t->integer('field_id');

      $t->string('attribute');

      $t->text('value');

      $t->datetime('created_at');

      $t->datetime('updated_at');

      $this->addTable($t);

    }

    

    public function down() {

      $this->removeTable('eav');

    }

    

}



Anyone know what happens?

Thanks.