Skip to content

Commit

Permalink
Merge pull request #281 from dala00/add-after-attribute
Browse files Browse the repository at this point in the history
Add 'after' attribute to migration_diff
  • Loading branch information
HavokInspiration authored Dec 30, 2016
2 parents ef0a194 + e58655f commit e50eafd
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/Shell/Task/MigrationDiffTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ protected function getColumns()
// brand new columns
$addedColumns = array_diff($currentColumns, $oldColumns);
foreach ($addedColumns as $columnName) {
$this->templateData[$table]['columns']['add'][$columnName] = $currentSchema->column($columnName);
$column = $currentSchema->column($columnName);
$key = array_search($columnName, $currentColumns);
if ($key > 0) {
$column['after'] = $currentColumns[$key - 1];
}
$this->templateData[$table]['columns']['add'][$columnName] = $column;
}

// changes in columns meta-data
Expand Down Expand Up @@ -256,9 +261,13 @@ protected function getColumns()
}
$removedColumns = array_diff($oldColumns, $currentColumns);
if (!empty($removedColumns)) {
foreach ($removedColumns as $column) {
$this->templateData[$table]['columns']['remove'][$column] =
$this->dumpSchema[$table]->column($column);
foreach ($removedColumns as $columnName) {
$column = $this->dumpSchema[$table]->column($columnName);
$key = array_search($columnName, $oldColumns);
if ($key > 0) {
$column['after'] = $oldColumns[$key - 1];
}
$this->templateData[$table]['columns']['remove'][$columnName] = $column;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/View/Helper/MigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ public function getColumnOption($options)
'null',
'comment',
'autoIncrement',
'precision'
'precision',
'after'
]);
$columnOptions = array_intersect_key($options, $wantedOptions);
if (empty($columnOptions['comment'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function up()

$this->table('articles')
->addColumn('the_text', 'text', [
'after' => 'title',
'default' => null,
'length' => null,
'null' => false,
Expand All @@ -25,6 +26,7 @@ public function down()

$this->table('articles')
->addColumn('excerpt', 'text', [
'after' => 'title',
'default' => null,
'length' => null,
'null' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function up()

$this->table('articles')
->addColumn('the_text', 'text', [
'after' => 'title',
'default' => null,
'length' => null,
'null' => false,
Expand All @@ -25,6 +26,7 @@ public function down()

$this->table('articles')
->addColumn('excerpt', 'text', [
'after' => 'title',
'default' => null,
'length' => null,
'null' => false,
Expand Down
1 change: 1 addition & 0 deletions tests/comparisons/Diff/simple/the_diff_simple_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function up()

$this->table('articles')
->addColumn('user_id', 'integer', [
'after' => 'name',
'default' => null,
'length' => 11,
'null' => false,
Expand Down
1 change: 1 addition & 0 deletions tests/comparisons/Diff/simple/the_diff_simple_pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function up()

$this->table('articles')
->addColumn('user_id', 'integer', [
'after' => 'name',
'default' => null,
'length' => 10,
'null' => false,
Expand Down
2 changes: 2 additions & 0 deletions tests/comparisons/Diff/the_diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function up()

$this->table('articles')
->addColumn('category_id', 'integer', [
'after' => 'user_id',
'default' => null,
'length' => 11,
'null' => false,
Expand Down Expand Up @@ -131,6 +132,7 @@ public function down()

$this->table('articles')
->addColumn('content', 'text', [
'after' => 'rating',
'default' => null,
'length' => null,
'null' => false,
Expand Down
2 changes: 2 additions & 0 deletions tests/comparisons/Diff/the_diff_mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function up()

$this->table('articles')
->addColumn('category_id', 'integer', [
'after' => 'user_id',
'default' => null,
'length' => 11,
'null' => false,
Expand Down Expand Up @@ -131,6 +132,7 @@ public function down()

$this->table('articles')
->addColumn('content', 'text', [
'after' => 'rating',
'default' => null,
'length' => null,
'null' => false,
Expand Down
2 changes: 2 additions & 0 deletions tests/comparisons/Diff/the_diff_pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function up()

$this->table('articles')
->addColumn('category_id', 'integer', [
'after' => 'user_id',
'default' => null,
'length' => 10,
'null' => false,
Expand Down Expand Up @@ -131,6 +132,7 @@ public function down()

$this->table('articles')
->addColumn('content', 'text', [
'after' => 'rating',
'default' => null,
'length' => null,
'null' => false,
Expand Down

0 comments on commit e50eafd

Please sign in to comment.