Skip to content

Commit 9310dc6

Browse files
committed
Fix failing tests
1 parent 9ef528c commit 9310dc6

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

src/lib/migrations/MysqlMigrationBuilder.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,16 @@ public function setPositions()
316316
continue;
317317
}
318318

319-
if (count($wantNames) !== count($haveNames)) {
320-
// check if only new columns are added without any explicit position change
321-
$namesForCreate = array_diff($wantNames, $haveNames);
322-
if ($namesForCreate && $haveNames === array_values(array_diff($wantNames, $namesForCreate))) {
323-
continue;
324-
}
319+
// // check if only new columns are added without any explicit position change
320+
$namesForCreate = array_diff($wantNames, $haveNames);
321+
if ($namesForCreate && $haveNames === array_values(array_diff($wantNames, $namesForCreate))) {
322+
continue;
323+
}
325324

326-
// check if only existing columns are deleted without any explicit position change
327-
$namesForDrop = array_diff($haveNames, $wantNames);
328-
if ($namesForDrop && $wantNames === array_values(array_diff($haveNames, $namesForDrop))) {
329-
continue;
330-
}
325+
// check if only existing columns are deleted without any explicit position change
326+
$namesForDrop = array_diff($haveNames, $wantNames);
327+
if ($namesForDrop && $wantNames === array_values(array_diff($haveNames, $namesForDrop))) {
328+
continue;
331329
}
332330

333331
if (is_int(array_search([$column->toPosition['index'], $column->fromPosition['index']], $takenIndices))) {

tests/unit/IssueFixTest.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,14 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
530530
{
531531
public function up()
532532
{
533-
$this->dropColumn('{{%fruits}}', 'colour');
534533
$this->dropColumn('{{%fruits}}', 'size');
534+
$this->dropColumn('{{%fruits}}', 'colour');
535535
}
536536
537537
public function down()
538538
{
539-
$this->addColumn('{{%fruits}}', 'size', $this->text()->notNull());
540539
$this->addColumn('{{%fruits}}', 'colour', $this->text()->notNull()->after('description'));
540+
$this->addColumn('{{%fruits}}', 'size', $this->text()->notNull());
541541
}
542542
}
543543

@@ -639,14 +639,14 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
639639
{
640640
public function up()
641641
{
642-
$this->dropColumn('{{%fruits}}', 'description');
643642
$this->dropColumn('{{%fruits}}', 'colour');
643+
$this->dropColumn('{{%fruits}}', 'description');
644644
}
645645
646646
public function down()
647647
{
648-
$this->addColumn('{{%fruits}}', 'colour', $this->text()->notNull());
649648
$this->addColumn('{{%fruits}}', 'description', $this->text()->notNull()->after('name'));
649+
$this->addColumn('{{%fruits}}', 'colour', $this->text()->notNull());
650650
}
651651
}
652652

@@ -693,14 +693,14 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
693693
{
694694
public function up()
695695
{
696-
$this->dropColumn('{{%fruits}}', 'name');
697696
$this->dropColumn('{{%fruits}}', 'colour');
697+
$this->dropColumn('{{%fruits}}', 'name');
698698
}
699699
700700
public function down()
701701
{
702-
$this->addColumn('{{%fruits}}', 'colour', $this->text()->notNull()->after('description'));
703702
$this->addColumn('{{%fruits}}', 'name', $this->text()->notNull()->after('id'));
703+
$this->addColumn('{{%fruits}}', 'colour', $this->text()->notNull()->after('description'));
704704
}
705705
}
706706

@@ -752,20 +752,24 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
752752
{
753753
public function up()
754754
{
755-
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('id'));
756-
$this->alterColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
755+
$this->dropColumn('{{%fruits}}', 'col_6');
756+
$this->dropColumn('{{%fruits}}', 'size');
757+
$this->dropColumn('{{%fruits}}', 'colour');
758+
$this->dropColumn('{{%fruits}}', 'description');
757759
}
758760
759761
public function down()
760762
{
761-
$this->alterColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
762-
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('description'));
763+
$this->addColumn('{{%fruits}}', 'description', $this->text()->null());
764+
$this->addColumn('{{%fruits}}', 'colour', $this->text()->null());
765+
$this->addColumn('{{%fruits}}', 'size', $this->text()->null());
766+
$this->addColumn('{{%fruits}}', 'col_6', $this->text()->null());
763767
}
764768
}
765769

766770
PHP;
767771

768-
$this->for58($schema, $expected, $columns, ['Mysql', 'Mariadb']);
772+
$this->for58($schema, $expected, $columns, ['Mysql']);
769773
}
770774

771775
// ------------ Add
@@ -1169,11 +1173,6 @@ public function test58Move1Add1Del1Col()
11691173
'description' => 'text null',
11701174
'colour' => 'text null',
11711175
'size' => 'text null',
1172-
// 'col_6' => 'text null',
1173-
// 'col_7' => 'text null',
1174-
// 'col_8' => 'text null',
1175-
// 'col_9' => 'text null',
1176-
11771176
];
11781177

11791178
$schema = <<<YAML
@@ -1189,7 +1188,7 @@ public function test58Move1Add1Del1Col()
11891188
id:
11901189
type: integer
11911190
colour:
1192-
type: string
1191+
type: string
11931192
name:
11941193
type: string
11951194
description:
@@ -1214,14 +1213,20 @@ class m200000_000000_change_table_fruits extends \yii\db\Migration
12141213
{
12151214
public function up()
12161215
{
1216+
$this->addColumn('{{%fruits}}', 'col_6', $this->text()->null());
1217+
$this->dropColumn('{{%fruits}}', 'size');
12171218
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('id'));
1218-
$this->alterColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
1219+
$this->alterColumn('{{%fruits}}', 'name', $this->text()->null()->after('colour'));
1220+
$this->alterColumn('{{%fruits}}', 'description', $this->text()->null()->after('name'));
12191221
}
12201222
12211223
public function down()
12221224
{
1223-
$this->alterColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
1225+
$this->alterColumn('{{%fruits}}', 'description', $this->text()->null()->after('name'));
1226+
$this->alterColumn('{{%fruits}}', 'name', $this->text()->null()->after('id'));
12241227
$this->alterColumn('{{%fruits}}', 'colour', $this->text()->null()->after('description'));
1228+
$this->addColumn('{{%fruits}}', 'size', $this->text()->null()->after('colour'));
1229+
$this->dropColumn('{{%fruits}}', 'col_6');
12251230
}
12261231
}
12271232

0 commit comments

Comments
 (0)