I have tried safeUp()
— it doesn’t work.
public function safeUp()
{
$table = '{{products}}';
$column = 'color_set';
$type = "SET('white', 'lightgray', 'gray', 'darkgray', 'black', "
. "'red', 'orange', 'gold', 'yellow', 'chartreuse', 'green', "
. "'aquamarine', 'cyan', 'dodgerblue', 'blue', 'mediumpurple', "
. "'purple', 'magenta', 'deeppink', 'crimson', 'darkred', "
. "'chocolate', 'olive', 'darkgreen', 'teal', 'darkblue', "
. "'indigo', 'darkmagenta', 'beige', 'pink')";
$time = microtime(true);
$this->addColumn($table, $column, $type);
$pairs = [
"שחור" => "black",
"אפור" => "gray",
"אדום \\ לבן" => "red, white",
// skipped
];
foreach ($pairs as $hebrew => $english) {
$this->update(
$table,
[ $column => $english ],
'color = :color',
[ ':color' => $hebrew ],
);
}
}
This migration adds a column and then tries to update it. When errors appeared, migration are terminated but transaction not rolled back, new column remains in the table.
These operations was performed on InnoDB table in MySQL 5.7. I suppose that this engine supports transactions.
UPDATE: I’ve fixed that script, it performs queries without errors but I had to replace safeUp()
with up()
because I’ve got an exception after last query have been executed:
Exception: There is no active transaction