mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge pull request #9175 from CakeDC/issue/9174
Fix CakeSchema compare when changing field length to the default one
This commit is contained in:
commit
b17d580ec2
2 changed files with 60 additions and 0 deletions
|
@ -487,6 +487,9 @@ class CakeSchema extends Object {
|
||||||
foreach ($fields as $field => $value) {
|
foreach ($fields as $field => $value) {
|
||||||
if (!empty($old[$table][$field])) {
|
if (!empty($old[$table][$field])) {
|
||||||
$diff = $this->_arrayDiffAssoc($value, $old[$table][$field]);
|
$diff = $this->_arrayDiffAssoc($value, $old[$table][$field]);
|
||||||
|
if (empty($diff)) {
|
||||||
|
$diff = $this->_arrayDiffAssoc($old[$table][$field], $value);
|
||||||
|
}
|
||||||
if (!empty($diff) && $field !== 'indexes' && $field !== 'tableParameters') {
|
if (!empty($diff) && $field !== 'indexes' && $field !== 'tableParameters') {
|
||||||
$tables[$table]['change'][$field] = $value;
|
$tables[$table]['change'][$field] = $value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -953,6 +953,63 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
$this->assertEquals($expected, $compare, 'Invalid SQL, datetime does not have length');
|
$this->assertEquals($expected, $compare, 'Invalid SQL, datetime does not have length');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test comparing with field length/limit changed from some non-default value to the default
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCompareLimitToDefault() {
|
||||||
|
$old = array(
|
||||||
|
'posts' => array(
|
||||||
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 1, 'key' => 'primary'),
|
||||||
|
'author_id' => array('type' => 'integer', 'null' => false, 'limit' => 5),
|
||||||
|
'title' => array('type' => 'string', 'null' => true, 'length' => 45),
|
||||||
|
'indexes' => array(
|
||||||
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
||||||
|
),
|
||||||
|
'tableParameters' => array(
|
||||||
|
'charset' => 'latin1',
|
||||||
|
'collate' => 'latin1_general_ci'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$new = array(
|
||||||
|
'posts' => array(
|
||||||
|
'id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
|
||||||
|
'author_id' => array('type' => 'integer', 'null' => false),
|
||||||
|
'title' => array('type' => 'varchar', 'null' => true),
|
||||||
|
'indexes' => array(
|
||||||
|
'PRIMARY' => array('column' => 'id', 'unique' => true)
|
||||||
|
),
|
||||||
|
'tableParameters' => array(
|
||||||
|
'charset' => 'latin1',
|
||||||
|
'collate' => 'latin1_general_ci'
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$compare = $this->Schema->compare($old, $new);
|
||||||
|
$expected = array(
|
||||||
|
'posts' => array(
|
||||||
|
'change' => array(
|
||||||
|
'id' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'null' => false,
|
||||||
|
'key' => 'primary'
|
||||||
|
),
|
||||||
|
'author_id' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'null' => false,
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'type' => 'varchar',
|
||||||
|
'null' => true,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected, $compare, 'Invalid SQL, field length change not detected');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testSchemaLoading method
|
* testSchemaLoading method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue