fixed migration
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user