getEnvironment() == "thetool") { $table = $this->table("AssetManagement"); $table->renameColumn('imageId', 'mainImageId'); $table->changeColumn('mainImageId', 'integer', [ 'null' => true, 'default' => null, 'comment' => 'Foreign key to the File table for the asset\'s main image', ]); $table->addColumn('imageIds', 'json', [ 'null' => true, 'default' => null, 'after' => 'mainImageId', 'comment' => 'An array of file IDs for all asset images', ]); $table->update(); $this->execute(" UPDATE `AssetManagement` SET `imageIds` = JSON_ARRAY(`mainImageId`) WHERE `mainImageId` IS NOT NULL; "); } } public function down(): void { if ($this->getEnvironment() == "thetool") { $table = $this->table("AssetManagement"); $this->execute(" UPDATE `AssetManagement` SET `mainImageId` = JSON_UNQUOTE(JSON_EXTRACT(`imageIds`, '$[0]')) WHERE JSON_TYPE(`imageIds`) = 'ARRAY' AND JSON_LENGTH(`imageIds`) > 0; "); $table->removeColumn('imageIds'); $table->renameColumn('mainImageId', 'imageId'); $table->changeColumn('imageId', 'integer', [ 'null' => true, 'default' => null, 'comment' => 'Foreign key to the File table for the asset\'s image', ]); $table->update(); } } }