You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -514,6 +517,8 @@ public function isDefaultValueChanged(
514
517
}
515
518
516
519
/**
520
+
* TODO move this method to MysqlMigrationBuilder
521
+
* Only for MySQL and MariaDB
517
522
* Given a column, compute its previous column name present in OpenAPI schema
518
523
* @return ?string
519
524
* `null` if column is added at last
@@ -528,24 +533,26 @@ public function findPosition(ColumnSchema $column, bool $forDrop = false): ?stri
528
533
if ($key > 0) {
529
534
$prevColName = $columnNames[$key-1];
530
535
531
-
if (!isset($columnNames[$key+1])) { // if new col is added at last then no need to add 'AFTER' SQL part. This is checked as if next column is present or not
536
+
if (!$forDrop && !isset($columnNames[$key+1])) { // if new col is added at last then no need to add 'AFTER' SQL part. This is checked as if next column is present or not
532
537
returnnull;
533
538
}
534
539
535
-
// in case of `down()` code of migration, putting 'after <colName>' in add column statmenet is erroneous because <colName> may not exist.
540
+
// in case of `down()` code of migration, putting 'after <colName>' in add column statement is erroneous because <colName> may not exist.
536
541
// Example: From col a, b, c, d, if I drop c and d then their migration code will be generated like:
537
542
// `up()` code
538
543
// drop c
539
544
// drop d
540
545
// `down()` code
541
-
// add d after c (c does not exist! Error!)
542
-
// add c
546
+
// add d after c (c does not exist! Error!) (TODO check if c is present in newColumn)
547
+
// add c after b (can fix this issue) TODO
543
548
if ($forDrop) {
544
-
returnnull;
549
+
// return null; // TODO this case can be fixed
545
550
}
546
551
547
-
548
-
returnself::POS_AFTER . '' . $prevColName;
552
+
if (array_key_exists($prevColName, $this->newColumns)) {
553
+
returnself::POS_AFTER . '' . $prevColName;
554
+
}
555
+
returnnull;
549
556
550
557
// if no `$columnSchema` is found, previous column does not exist. This happens when 'after column' is not yet added in migration or added after currently undertaken column
551
558
} elseif ($key === 0) {
@@ -574,4 +581,20 @@ public function modifyDesiredInContextOfDesiredFromDb(ColumnSchema $desired, Col
Copy file name to clipboardExpand all lines: tests/specs/issue_fix/58_create_migration_for_column_position_change_if_a_field_position_is_changed_in_spec/index.yml
0 commit comments