48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class MakePauseReasonNullable extends AbstractMigration
|
|
{
|
|
public function up(): void
|
|
{
|
|
$table = $this->table('production_pauses');
|
|
|
|
// 1. rimuovo la FK che blocca la modifica della colonna
|
|
$table->dropForeignKey('reason_id')->update();
|
|
|
|
// 2. rendo la colonna nullable, mantenendo il tipo reale (tinyint unsigned)
|
|
$table->changeColumn('reason_id', 'integer', [
|
|
'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY,
|
|
'signed' => false,
|
|
'null' => true,
|
|
])->update();
|
|
|
|
// 3. ricreo la FK
|
|
$table->addForeignKey('reason_id', 'pause_reasons', 'id', [
|
|
'delete' => 'SET_NULL',
|
|
'update' => 'NO_ACTION',
|
|
])->update();
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
$table = $this->table('production_pauses');
|
|
|
|
$table->dropForeignKey('reason_id')->update();
|
|
|
|
$table->changeColumn('reason_id', 'integer', [
|
|
'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY,
|
|
'signed' => false,
|
|
'null' => false,
|
|
])->update();
|
|
|
|
$table->addForeignKey('reason_id', 'pause_reasons', 'id', [
|
|
'delete' => 'NO_ACTION',
|
|
'update' => 'NO_ACTION',
|
|
])->update();
|
|
}
|
|
}
|