getEnvironment() == "thetool") { // Create the main asset table $assetManagement = $this->table('AssetManagement', ['id' => false, 'primary_key' => ['id']]); $assetManagement->addColumn('id', 'integer', ['identity' => true, 'signed' => false]) ->addColumn('name', 'string', ['limit' => 255, 'null' => false, 'comment' => 'Name of the asset or device']) ->addColumn('assetNumber', 'string', ['limit' => 255, 'null' => false, 'comment' => 'Unique identifier for the asset (e.g., XI001)']) ->addColumn('location', 'string', ['limit' => 255, 'null' => false, 'comment' => 'The primary storage location of the asset']) ->addColumn('serviceDueDate', 'integer', ['null' => true, 'comment' => 'Date when the next service is due']) ->addColumn('create', 'integer', ['null' => false, 'comment' => 'Unix timestamp of creation']) ->addColumn('createBy', 'integer', ['null' => false, 'comment' => 'User ID of the creator']) ->addIndex(['assetNumber'], ['unique' => true, 'name' => 'assetNumber']) ->create(); // Create the journal table for asset borrowing and returning $assetManagementJournal = $this->table('AssetManagementJournal', ['id' => false, 'primary_key' => ['id']]); $assetManagementJournal->addColumn('id', 'integer', ['identity' => true, 'signed' => false]) ->addColumn('assetId', 'integer', ['null' => false, 'comment' => 'Foreign key to the AssetManagement table']) ->addColumn('userId', 'integer', ['null' => false, 'comment' => 'User ID of the employee who borrowed the asset']) ->addColumn('site', 'string', ['limit' => 255, 'null' => false, 'comment' => 'The construction site or project where the asset is being used']) ->addColumn('borrowDate', 'integer', ['null' => false, 'comment' => 'Unix timestamp when the asset was borrowed']) ->addColumn('returnDate', 'integer', ['null' => true, 'comment' => 'Unix timestamp when the asset was returned']) ->addColumn('borrowReason', 'text', ['null' => false, 'comment' => 'Reason for borrowing the asset']) ->addColumn('returnReason', 'text', ['null' => true, 'comment' => 'Notes or reason for returning the asset']) ->addColumn('createBy', 'integer', ['null' => false, 'comment' => 'User ID of the person who created this journal entry']) ->addColumn('create', 'integer', ['null' => false, 'comment' => 'Unix timestamp of journal entry creation']) ->addIndex(['assetId'], ['name' => 'assetId']) ->addIndex(['userId'], ['name' => 'userId']) ->create(); } } /** * Rollback the migration by dropping the tables. */ public function down(): void { // Environment check to ensure this migration only runs on the specified environment. if ($this->getEnvironment() == "thetool") { // Drop tables in reverse order of creation to avoid foreign key issues. $this->table('AssetManagementJournal')->drop()->save(); $this->table('AssetManagement')->drop()->save(); } } }