Skip to content

Commit

Permalink
Merge pull request #293 from cakephp/issue-274
Browse files Browse the repository at this point in the history
When baking a diff, the attribute `length` / `limit`, `default` and ` null` are always included in `changeColumn` instructions.
  • Loading branch information
lorenzo authored Jan 1, 2017
2 parents c33ba27 + ce72a96 commit bed3b4d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/Shell/Task/MigrationDiffTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,24 @@ protected function getColumns()
) {
$changedAttributes = array_diff($column, $oldColumn);

if (!isset($changedAttributes['type'])) {
$changedAttributes['type'] = $column['type'];
foreach (['type', 'length', 'null', 'default'] as $attribute) {
$phinxAttributeName = $attribute;
if ($attribute == 'length') {
$phinxAttributeName = 'limit';
}
if (!isset($changedAttributes[$phinxAttributeName])) {
$changedAttributes[$phinxAttributeName] = $column[$attribute];
}
}

if (isset($changedAttributes['length'])) {
if (!isset($changedAttributes['limit'])) {
$changedAttributes['limit'] = $changedAttributes['length'];
}

unset($changedAttributes['length']);
}

$this->templateData[$table]['columns']['changed'][$columnName] = $changedAttributes;
}
}
Expand Down
10 changes: 8 additions & 2 deletions tests/comparisons/Diff/the_diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ public function up()

$this->table('articles')
->removeColumn('content')
->changeColumn('title', 'text')
->changeColumn('title', 'text', [
'default' => null,
'limit' => null,
'null' => false,
])
->changeColumn('name', 'string', [
'length' => 50,
'default' => null,
'limit' => 50,
'null' => false,
])
->update();

Expand Down
10 changes: 8 additions & 2 deletions tests/comparisons/Diff/the_diff_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ public function up()

$this->table('articles')
->removeColumn('content')
->changeColumn('title', 'text')
->changeColumn('title', 'text', [
'default' => null,
'limit' => null,
'null' => false,
])
->changeColumn('name', 'string', [
'length' => 50,
'default' => null,
'limit' => 50,
'null' => false,
])
->update();

Expand Down
10 changes: 8 additions & 2 deletions tests/comparisons/Diff/the_diff_pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ public function up()

$this->table('articles')
->removeColumn('content')
->changeColumn('title', 'text')
->changeColumn('title', 'text', [
'default' => null,
'limit' => null,
'null' => false,
])
->changeColumn('name', 'string', [
'length' => 50,
'default' => null,
'limit' => 50,
'null' => false,
])
->update();

Expand Down

0 comments on commit bed3b4d

Please sign in to comment.