From 328772f8dacd0588a5f6d9a683b3fa4ed15875ca Mon Sep 17 00:00:00 2001 From: solocla Date: Mon, 21 Sep 2026 09:28:17 +0200 Subject: [PATCH] fixed migration --- ...60915073019_make_pause_reason_nullable.php | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/db/migrations/20260915073019_make_pause_reason_nullable.php b/db/migrations/20260915073019_make_pause_reason_nullable.php index 8ecbbece..e0782f57 100644 --- a/db/migrations/20260915073019_make_pause_reason_nullable.php +++ b/db/migrations/20260915073019_make_pause_reason_nullable.php @@ -8,17 +8,40 @@ final class MakePauseReasonNullable extends AbstractMigration { public function up(): void { - // La FK su reason_id è già stata rimossa e la colonna è già nullable. - // Garantisco lo stato finale in modo idempotente, senza ricreare la FK. - $this->table('production_pauses') - ->changeColumn('reason_id', 'integer', ['null' => true]) - ->update(); + $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 { - $this->table('production_pauses') - ->changeColumn('reason_id', 'integer', ['null' => false]) - ->update(); + $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(); } }