Files
thetool/db/migrations/20250629140000_rml_workorder_create.php
2025-06-29 20:32:28 +02:00

67 lines
4.1 KiB
PHP

<?php /** @noinspection ALL */
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class RmlWorkorderCreate extends AbstractMigration {
public function up(): void {
if ($this->getEnvironment() == "thetool") {
$table = $this->table("WorkerPermission");
$table->addColumn("canRMLAdmin", "enum", ["null" => false, "values" => ['false', 'true'], "default" => "false", "after" => "canSuperexpert"]);
$table->update();
}
if ($this->getEnvironment() == "addressdb") {
// Create RMLWorkorderCompany table
$rmlWorkorderCompany = $this->table('RMLWorkorderCompany', ['id' => 'id', 'primary_key' => 'id']);
$rmlWorkorderCompany->addColumn('addressId', 'integer', ['null' => false, 'comment' => 'FK to the Address table, identifying the company.'])
->addColumn('name', 'string', ['limit' => 255, 'null' => false, 'comment' => 'Cached company name for easy display.'])
->addColumn('create', 'integer', ['null' => false])
->addColumn('createBy', 'integer', ['null' => false])
->addIndex(['addressId'], ['unique' => true, 'name' => 'addressId_unique'])
->create();
// Create RMLWorkorder table
$rmlWorkorder = $this->table('RMLWorkorder', ['id' => 'id', 'primary_key' => 'id']);
$rmlWorkorder->addColumn('preorderId', 'integer', ['null' => false, 'comment' => 'FK to the Preorder that triggered this work order.'])
->addColumn('companyId', 'integer', ['null' => true, 'comment' => 'FK to RMLWorkorderCompany, assigned by an RML admin.'])
->addColumn('status', 'string', ['limit' => 50, 'null' => false, 'default' => 'new', 'comment' => 'Workflow status: new, assigned, scheduled, documented, completed.'])
->addColumn('assignmentDate', 'integer', ['null' => true, 'comment' => 'Timestamp when the order was assigned.'])
->addColumn('deadlineDate', 'integer', ['null' => true, 'comment' => 'Timestamp for the 6-week completion deadline.'])
->addColumn('appointmentDate', 'integer', ['null' => true, 'comment' => 'The date scheduled by the company for the work.'])
->addColumn('create', 'integer', ['null' => false])
->addColumn('createBy', 'integer', ['null' => false])
->addIndex(['preorderId'], ['name' => 'preorderId_idx'])
->addIndex(['companyId'], ['name' => 'companyId_idx'])
->addIndex(['status'], ['name' => 'status_idx'])
->create();
// Create RMLWorkorderDocumentation table
$rmlWorkorderDocumentation = $this->table('RMLWorkorderDocumentation', ['id' => 'id', 'primary_key' => 'id']);
$rmlWorkorderDocumentation->addColumn('workorderId', 'integer', ['null' => false, 'comment' => 'FK to the RMLWorkorder.'])
->addColumn('fileId', 'integer', ['null' => false, 'comment' => 'FK to the main File table after upload.'])
->addColumn('description', 'text', ['null' => true, 'comment' => 'User-provided description for the file.'])
->addColumn('documentType', 'string', ['limit' => 100, 'null' => false, 'comment' => 'Categorizes the upload, e.g., photo_before, measurement_protocol.'])
->addColumn('create', 'integer', ['null' => false])
->addColumn('createBy', 'integer', ['null' => false])
->addIndex(['workorderId'], ['name' => 'workorderId_idx'])
->create();
}
}
public function down(): void {
if ($this->getEnvironment() == "thetool") {
$table = $this->table("WorkerPermission");
$table->removeColumn("canRMLAdmin");
$table->save();
}
if ($this->getEnvironment() == "addressdb") {
// Drop tables in reverse order of creation (or dependency)
$this->table('RMLWorkorderDocumentation')->drop();
$this->table('RMLWorkorder')->drop();
$this->table('RMLWorkorderCompany')->drop();
}
}
}