Files
thetool/db/migrations/20250826160000_rmlworkorder_multi_tenant.php
2025-08-26 17:25:04 +02:00

80 lines
3.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class RmlworkorderMultiTenant extends AbstractMigration
{
public function up(): void
{
if ($this->getEnvironment() !== "thetool") {
return;
}
$companyTable = $this->table('RMLWorkorderCompany');
if (!$companyTable->hasColumn('visibleForAddressId')) {
$companyTable->addColumn('visibleForAddressId', 'text', ['null' => true, 'default' => null, 'after' => 'name'])->save();
}
if (!$this->hasTable('RMLWorkorderTenantConfig')) {
$this->table('RMLWorkorderTenantConfig', ['id' => false, 'primary_key' => ['id']])
->addColumn('id', 'integer', ['identity' => true, 'signed' => false])
->addColumn('addressId', 'integer')
->addColumn('name', 'string', ['limit' => 255])
->addColumn('documentationTypes', 'json')
->addColumn('workorderCreationFilters', 'json')
->addColumn('create', 'integer')
->addColumn('createBy', 'integer')
->addIndex(['addressId'], ['name' => 'addressId_idx'])
->create();
}
$docTypes = [
['value' => 'photo_hup_mounted', 'text' => 'Foto vom montierten HÜP'],
['value' => 'photo_hup_open', 'text' => 'Foto von dem offenen HÜP'],
['value' => 'photo_splice_cassette_hup', 'text' => 'Foto der Spleißkassette HÜP'],
['value' => 'photo_splice_cassette_fcp', 'text' => 'Foto der Spleißkassette - FCP'],
['value' => 'photo_hup_closed_stickers', 'text' => 'Foto vom geschlossenen HÜP mit allen Aufklebern'],
['value' => 'photo_fcp_labeled', 'text' => 'Foto vom FCP beschriftet'],
['value' => 'photo_patch_position_osp', 'text' => 'Foto der Patch-Position - OSP-Seite'],
['value' => 'photo_patch_position_anb', 'text' => 'Foto der Patch-Position - ANB-Seite'],
['value' => 'measurement_protocol_otdr', 'text' => 'ODTR Messung (1310nm & 1550nm)'],
];
$workorderFilters = [
'status_code' => 220,
'preorder_status_flags_all' => [3, 5],
];
$this->table('RMLWorkorderTenantConfig')->insert([
[
'id' => 1,
'addressId' => 4807,
'name' => 'RML Standard',
'documentationTypes' => json_encode($docTypes),
'workorderCreationFilters' => json_encode($workorderFilters),
'create' => 1724704509,
'createBy' => 1
]
])->save();
$this->execute("UPDATE RMLWorkorderCompany SET visibleForAddressId = '[4807]' WHERE visibleForAddressId IS NULL;");
}
public function down(): void
{
if ($this->getEnvironment() !== "thetool") {
return;
}
if ($this->hasTable('RMLWorkorderTenantConfig')) {
$this->table('RMLWorkorderTenantConfig')->drop()->save();
}
$companyTable = $this->table('RMLWorkorderCompany');
if ($companyTable->hasColumn('visibleForAddressId')) {
$companyTable->removeColumn('visibleForAddressId')->save();
}
}
}