120 lines
3.9 KiB
PHP
120 lines
3.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Phinx\Migration\AbstractMigration;
|
|
|
|
final class AssetManagementSchemaV2 extends AbstractMigration
|
|
{
|
|
/**
|
|
* Implements schema changes for Asset Management v2
|
|
*/
|
|
public function up(): void
|
|
{
|
|
if($this->getEnvironment() == "thetool") {
|
|
// 1. Add columns to AssetManagement table
|
|
$assetManagement = $this->table('AssetManagement');
|
|
$assetManagement
|
|
->addColumn('imageId', 'integer', [
|
|
'null' => true,
|
|
'default' => null,
|
|
'signed' => false,
|
|
'comment' => 'Foreign key to the File table for the asset image',
|
|
'after' => 'description'
|
|
])
|
|
->addColumn('mustReturnDate', 'integer', [
|
|
'null' => true,
|
|
'default' => null,
|
|
'signed' => false,
|
|
'comment' => 'Mandatory return date for rented items (Unix timestamp)',
|
|
'after' => 'serviceDueDate'
|
|
])
|
|
->update();
|
|
|
|
// 2. Add column to AssetManagementJournal table
|
|
$journalTable = $this->table('AssetManagementJournal');
|
|
$journalTable
|
|
->addColumn('expectedReturnDate', 'integer', [
|
|
'null' => true,
|
|
'default' => null,
|
|
'signed' => false,
|
|
'comment' => 'Expected return date set upon borrowing (Unix timestamp)',
|
|
'after' => 'borrowDate'
|
|
])
|
|
->update();
|
|
|
|
// 3. Create AssetManagementReservation table
|
|
$reservationTable = $this->table('AssetManagementReservation', [
|
|
'id' => false,
|
|
'primary_key' => ['id'],
|
|
'engine' => 'InnoDB',
|
|
'comment' => 'Asset reservation system'
|
|
]);
|
|
|
|
$reservationTable
|
|
->addColumn('id', 'integer', [
|
|
'identity' => true,
|
|
'signed' => false,
|
|
'null' => false
|
|
])
|
|
->addColumn('assetId', 'integer', [
|
|
'signed' => false,
|
|
'null' => false,
|
|
'comment' => 'Foreign key to the AssetManagement table'
|
|
])
|
|
->addColumn('userId', 'integer', [
|
|
'signed' => false,
|
|
'null' => false,
|
|
'comment' => 'User ID of the employee who made the reservation'
|
|
])
|
|
->addColumn('startDate', 'integer', [
|
|
'signed' => false,
|
|
'null' => false,
|
|
'comment' => 'Start date of the reservation (Unix timestamp)'
|
|
])
|
|
->addColumn('endDate', 'integer', [
|
|
'signed' => false,
|
|
'null' => true,
|
|
'default' => null,
|
|
'comment' => 'End date of the reservation (Unix timestamp). NULL means permanent.'
|
|
])
|
|
->addColumn('notes', 'text', [
|
|
'null' => true,
|
|
'default' => null,
|
|
'comment' => 'Notes for the reservation'
|
|
])
|
|
->addColumn('createBy', 'integer', [
|
|
'signed' => false,
|
|
'null' => false
|
|
])
|
|
->addColumn('create', 'integer', [
|
|
'signed' => false,
|
|
'null' => false
|
|
])
|
|
->addIndex(['assetId'])
|
|
->create();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reverts the schema changes
|
|
*/
|
|
public function down(): void
|
|
{
|
|
if($this->getEnvironment() == "thetool") {
|
|
// Remove columns from AssetManagement
|
|
$this->table('AssetManagement')
|
|
->removeColumn('imageId')
|
|
->removeColumn('mustReturnDate')
|
|
->update();
|
|
|
|
// Remove column from AssetManagementJournal
|
|
$this->table('AssetManagementJournal')
|
|
->removeColumn('expectedReturnDate')
|
|
->update();
|
|
|
|
// Drop reservation table
|
|
$this->table('AssetManagementReservation')->drop()->save();
|
|
}
|
|
}
|
|
}
|