diff --git a/src/Shell/Task/MigrationDiffTask.php b/src/Shell/Task/MigrationDiffTask.php index 7ca700ee..dc7fcd20 100644 --- a/src/Shell/Task/MigrationDiffTask.php +++ b/src/Shell/Task/MigrationDiffTask.php @@ -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; } } diff --git a/tests/comparisons/Diff/the_diff.php b/tests/comparisons/Diff/the_diff.php index 65e758bf..1352c9f5 100644 --- a/tests/comparisons/Diff/the_diff.php +++ b/tests/comparisons/Diff/the_diff.php @@ -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(); diff --git a/tests/comparisons/Diff/the_diff_mysql.php b/tests/comparisons/Diff/the_diff_mysql.php index 60c4d9da..e05001ad 100644 --- a/tests/comparisons/Diff/the_diff_mysql.php +++ b/tests/comparisons/Diff/the_diff_mysql.php @@ -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(); diff --git a/tests/comparisons/Diff/the_diff_pgsql.php b/tests/comparisons/Diff/the_diff_pgsql.php index cad96a4b..b189b5ae 100644 --- a/tests/comparisons/Diff/the_diff_pgsql.php +++ b/tests/comparisons/Diff/the_diff_pgsql.php @@ -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();