Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CakeSchema compare not detecting field length change when changing from some non-default value to the default one #9174

Closed
1 of 3 tasks
andrej-griniuk opened this issue Jul 26, 2016 · 1 comment

Comments

@andrej-griniuk
Copy link
Contributor

This is a:

  • bug
  • enhancement
  • feature-discussion (RFC)
  • CakePHP Version: 2.8.5.
  • Platform and Target: MySQL 5.6, PHP 5.6

What you did

Create a table with 'name' VARCHAR(45) column. Generate schema snapshot schema.php using Schema shell. For instance:

<?php
class AppSchema extends CakeSchema {

    public function before($event = array()) {
        return true;
    }

    public function after($event = array()) {
    }

    public $posts = array(
        'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => true, 'key' => 'primary'),
        'name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 45, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
        'indexes' => array(
            'PRIMARY' => array('column' => 'id', 'unique' => 1)
        ),
        'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB')
    );

} 

Generate it again and update schema_2.php removing length key on name column:

<?php
class AppSchema extends CakeSchema {

    public $file = 'schema_2.php';

    public function before($event = array()) {
        return true;
    }

    public function after($event = array()) {
    }

    public $posts = array(
        'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => true, 'key' => 'primary'),
        'name' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
        'indexes' => array(
            'PRIMARY' => array('column' => 'id', 'unique' => 1)
        ),
        'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB')
    );

} 

Run Console/cake schema update -s 2

Expected Behavior

Welcome to CakePHP v2.8.5 Console
---------------------------------------------------------------
App : app
Path: /var/www/cakephp2/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Comparing Database to Schema...

The following statements will run.
ALTER TABLE `cakephp2`.`posts`
        CHANGE `name` `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
Are you sure you want to alter the tables? (y/n)

Actual Behavior

Welcome to CakePHP v2.8.5 Console
---------------------------------------------------------------
App : app
Path: /var/www/cakephp2/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Comparing Database to Schema...
Schema is up to date.

P.S. pull request to come...

@markstory
Copy link
Member

Closing as a pull request is up now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants