69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
/**
|
|
* Aggiunge il flag `engine` alla tabella `routine` esistente (0 = legacy su file,
|
|
* 1 = motore generico basato su routine_step) e crea la tabella `routine_step`.
|
|
*
|
|
* Migrazione puramente additiva: le routine legacy esistenti (id 1..4) restano
|
|
* intatte e con engine = 0 continuano a funzionare come prima.
|
|
*/
|
|
final class AddEngineAndRoutineStep extends AbstractMigration
|
|
{
|
|
public function change(): void
|
|
{
|
|
// 1) Flag engine sulla tabella esistente `routine`
|
|
$routine = $this->table('routine');
|
|
if (!$routine->hasColumn('engine')) {
|
|
$routine
|
|
->addColumn('engine', 'boolean', [
|
|
'default' => 0,
|
|
'null' => false,
|
|
'comment' => '0 = routine legacy su file, 1 = motore generico (routine_step)',
|
|
'after' => 'filename',
|
|
])
|
|
->update();
|
|
}
|
|
|
|
// 2) Nuova tabella routine_step
|
|
if (!$this->hasTable('routine_step')) {
|
|
$table = $this->table('routine_step', [
|
|
'id' => 'idstep',
|
|
'signed' => false,
|
|
'engine' => 'InnoDB',
|
|
'collation' => 'utf8mb4_general_ci',
|
|
]);
|
|
|
|
$table
|
|
->addColumn('idroutine', 'integer', [
|
|
'null' => false,
|
|
'comment' => 'FK verso routine.idroutine',
|
|
])
|
|
->addColumn('step_order', 'integer', [
|
|
'default' => 1,
|
|
'null' => false,
|
|
'comment' => 'Ordine di esecuzione dello step nella routine',
|
|
])
|
|
->addColumn('operation', 'string', [
|
|
'limit' => 50,
|
|
'null' => false,
|
|
'comment' => 'Verbo operazione: merge, replace, trim, copy, clear, uppercase, lowercase',
|
|
])
|
|
->addColumn('params', 'text', [
|
|
'null' => true,
|
|
'comment' => 'Parametri operazione in formato JSON',
|
|
])
|
|
->addColumn('active', 'boolean', [
|
|
'default' => 1,
|
|
'null' => false,
|
|
'comment' => 'Se 0 lo step viene saltato',
|
|
])
|
|
->addIndex(['idroutine', 'step_order'], ['name' => 'idx_routine_order'])
|
|
->create();
|
|
}
|
|
}
|
|
}
|