#6330: Schema migrations and empty indexes
---------------------------+------------------------------------------------
    Reporter:  martin-k    |          Type:  Bug   
      Status:  new         |      Priority:  Medium
   Milestone:              |     Component:  Schema
     Version:              |      Severity:  Minor 
    Keywords:              |   Php_version:  PHP 5 
Cake_version:  1.2.2.8120  |  
---------------------------+------------------------------------------------
 I'm using schemas for automatic DB migrations. I found a strange case when
 migrating from:

 {{{
 var $clubs_users = array(
                 'club_id' => array('type' => 'integer', 'null' => false),
                 'user_id' => array('type' => 'integer', 'null' => false),
                 'indexes' => array()
         );
 }}}

 (club users had only two columns and no primary key)

 to:
 {{{
 var $clubs_users = array(
                 'id' => array('type' => 'integer', 'null' => false,
 'default' => NULL, 'key' => 'primary'),
                 'club_id' => array('type' => 'integer', 'null' => false),
                 'user_id' => array('type' => 'integer', 'null' => false),
                 'indexes' => array('PRIMARY' => array('column' => 'id',
 'unique' => 1))
         );
 }}}
 (I added a primary key to clubs_users)

 When I tried to migrate I got the error:
 {{{
 1091: Can't DROP 'indexes'; check that column/key exists
 }}}

 This notice also popped out:
 {{{
 Notice (8): Undefined index:  drop [CORE/cake/libs/model/schema.php, line
 430]
 }}}


 It seems to happen because Schema::_compareIndexes is expected to return
 (false or) an array with two keys, 'add' and 'drop', but in this case
 there was only 'add'.


 I found out why - this is how _compareIndexes returns: (see last lines of
 cake/libs/model/schema.php)
 {{{
 return array_filter(compact('add', 'drop'));
 }}}

 Removing array_filter fixed the problem (the empty 'drop' is not removed
 from the array any more) but I don't know if it may have unexpected side-
 effects.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/6330>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to