Yii Framework Forum: Migrate table prefix - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Migrate table prefix Rate Topic: -----

#1 User is offline   Luiz Celso 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 13-April 12

Posted 02 May 2012 - 10:06 AM

Migrate generates the migration table with Yii' default prefix 'tbl_', not the one I set in the config/console.
0

#2 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 532
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 02 May 2012 - 02:25 PM

it only creates the table with its default name which is tbl_migration, you can configure 'migrationTable' property of MigrateCommand to have the table named like you want it.
1

#3 User is offline   Luiz Celso 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 13-April 12

Posted 02 May 2012 - 03:59 PM

 CeBe, on 02 May 2012 - 02:25 PM, said:

it only creates the table with its default name which is tbl_migration, you can configure 'migrationTable' property of MigrateCommand to have the table named like you want it.


I know that, CeBe.

It's only a suggestion: generate the migration table with the prefix defined in config/console.php.

But I think that I had put the in the wrong place. Sorry
0

#4 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 532
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 02 May 2012 - 05:26 PM

 Luiz Celso, on 02 May 2012 - 03:59 PM, said:

It's only a suggestion: generate the migration table with the prefix defined in config/console.php.


This has been discussed in a google code issue, but I couldn't find it anymore.
When default migration table name has the syntax to accept table prefix with {{ and }} it would not work on databases that have table prefix disabled.
0

#5 User is offline   Luiz Celso 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 13-April 12

Posted 03 May 2012 - 01:01 PM

 CeBe, on 02 May 2012 - 05:26 PM, said:

This has been discussed in a google code issue, but I couldn't find it anymore.
When default migration table name has the syntax to accept table prefix with {{ and }} it would not work on databases that have table prefix disabled.


Ok, tx!
0

#6 User is offline   jacmoe 

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

Posted 26 February 2013 - 07:33 PM

Is this going to be fixed in Yii 2 ?

Seriously, what's the problem?

If a prefix is set, migration should use it.

The old topic in the old issue tracker is here: https://code.google..../detail?id=3001
"Less noise - more signal"
0

#7 User is offline   PrplHaz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 108
  • Joined: 28-September 09
  • Location:Boston, MA

Posted 08 March 2013 - 01:42 PM

I just ran into this again....ended up with two migration tables, and had to back one out, then apply changes again and drop unused table. It seems a bit silly that it would use a default prefix of "tbl_" when there is a user-defined prefix already.

Is there at least a simple way to define migrationTable in config so that I don't have to specify it on the command line every time?
0

#8 User is offline   jacmoe 

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

Posted 08 March 2013 - 02:59 PM

What I'm doing to work around this is one line of code in my migrations:



class m130226_185845_initial_tables extends CDbMigration
{
	public function up()
	{

        if(! isset(Yii::app()->getDb()->tablePrefix)) { Yii::app()->getDb()->tablePrefix = ''; };


        $this->createTable('{{tablename}}', array( ......



For each up/down function.

Yii should do something like that out of the box, IMO.
"Less noise - more signal"
0

#9 User is offline   PrplHaz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 108
  • Joined: 28-September 09
  • Location:Boston, MA

Posted 08 March 2013 - 05:33 PM

 jacmoe, on 08 March 2013 - 02:59 PM, said:

What I'm doing to work around this is one line of code in my migrations:



class m130226_185845_initial_tables extends CDbMigration
{
	public function up()
	{

        if(! isset(Yii::app()->getDb()->tablePrefix)) { Yii::app()->getDb()->tablePrefix = ''; };


        $this->createTable('{{tablename}}', array( ......



For each up/down function.

Yii should do something like that out of the box, IMO.


I agree...it should. Are you doing anything to change the table where migrations are stored (tbl_migration)? It seems to me that it should be 'prefix_migration' as well....
0

#10 User is offline   jacmoe 

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

Posted 08 March 2013 - 08:35 PM

I am not. That would change a core component.
But the extra line of code in each function of the migration will make sure that the tables are created properly, respecting the table prefix (if any) set by the user.
I see no reason why migrations in Yii couldn't perform the same check and set operation. It seems unnecessary to make use explicitly set the table prefix for the migration table, if you ask me. :)
"Less noise - more signal"
0

#11 User is offline   asapconnections 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 25-June 13

Posted 25 June 2013 - 11:18 AM

 PrplHaz4, on 08 March 2013 - 01:42 PM, said:

I just ran into this again....ended up with two migration tables, and had to back one out, then apply changes again and drop unused table. It seems a bit silly that it would use a default prefix of "tbl_" when there is a user-defined prefix already.

Is there at least a simple way to define migrationTable in config so that I don't have to specify it on the command line every time?


Yes, you can set this in config/console.php like so (look under heading 'Configure Command Globally')

return array(
    ......
    'commandMap'=>array(
        'migrate'=>array(
            'class'=>'system.cli.commands.MigrateCommand',
            'migrationPath'=>'application.migrations',
            'migrationTable'=>'tbl_migration',
            'connectionID'=>'db',
            'templateFile'=>'application.migrations.template',
        ),
        ......
    ),
    ......
);

0

Share this topic:


Page 1 of 1
  • 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