fixed migration

This commit is contained in:
2026-09-21 09:28:17 +02:00
parent 06092e24aa
commit 328772f8da
@@ -8,17 +8,40 @@ final class MakePauseReasonNullable extends AbstractMigration
{ {
public function up(): void public function up(): void
{ {
// La FK su reason_id è già stata rimossa e la colonna è già nullable. $table = $this->table('production_pauses');
// Garantisco lo stato finale in modo idempotente, senza ricreare la FK.
$this->table('production_pauses') // 1. rimuovo la FK che blocca la modifica della colonna
->changeColumn('reason_id', 'integer', ['null' => true]) $table->dropForeignKey('reason_id')->update();
->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 public function down(): void
{ {
$this->table('production_pauses') $table = $this->table('production_pauses');
->changeColumn('reason_id', 'integer', ['null' => false])
->update(); $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();
} }
} }