Files
thetool/db/migrations/20251008140000_workorder_add_in_progress.php
2025-10-08 14:32:04 +02:00

75 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class WorkorderAddInProgress extends AbstractMigration {
public function up(): void {
if ($this->getEnvironment() !== 'thetool') return;
$this->table('Workorder')
->changeColumn('status', 'enum', [
'values' => [
'new',
'assigned',
'scheduled',
'in_progress',
'correction_requested',
'intervention_required',
'civil_engineering_required',
'civil_engineering_completed',
'problem_solved',
'documented',
'completed',
'cancelled',
'archived',
'charged'
],
'default' => 'new',
'null' => false,
])
->save();
// Update existing Workorders that are assigned or scheduled and already have documentation.
$this->execute("
UPDATE Workorder w
SET w.status = 'in_progress'
WHERE w.status IN ('assigned', 'scheduled')
AND EXISTS (
SELECT 1
FROM WorkorderDocumentation wd
WHERE wd.workorderId = w.id
)
");
}
public function down(): void {
if ($this->getEnvironment() !== 'thetool') return;
$this->table('Workorder')
->changeColumn('status', 'enum', [
'values' => [
'new',
'assigned',
'scheduled',
'correction_requested',
'intervention_required',
'civil_engineering_required',
'civil_engineering_completed',
'problem_solved',
'documented',
'completed',
'cancelled',
'archived',
'charged'
],
'default' => 'new',
'null' => false,
])
->save();
}
}