Support naming docker images on eggs; closes #4052

Bumps PTDL_v1 export images to PTDL_v2, updates the Minecraft specific eggs to use named images.
This commit is contained in:
DaneEveritt 2022-05-07 17:45:22 -04:00
parent 53207abcb3
commit c8faf64059
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
17 changed files with 212 additions and 261 deletions

View file

@ -0,0 +1,40 @@
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Migrations\Migration;
class MigrateEggImagesArrayToNewFormat extends Migration
{
/**
* Run the migrations. This will loop over every egg on the system and update the
* images array to both exist, and have key => value pairings to support naming the
* images provided.
*/
public function up()
{
DB::table('eggs')->select(['id', 'docker_images'])->cursor()->each(function ($egg) {
$images = is_null($egg->docker_images) ? [] : json_decode($egg->docker_images, true, 512, JSON_THROW_ON_ERROR);
$results = [];
foreach ($images as $key => $value) {
$results[is_int($key) ? $value : $key] = $value;
}
DB::table('eggs')->where('id', $egg->id)->update(['docker_images' => $results]);
});
}
/**
* Reverse the migrations. This just keeps the values from the docker images array.
*
* @return void
*/
public function down()
{
DB::table('eggs')->select(['id', 'docker_images'])->cursor()->each(function ($egg) {
DB::table('eggs')->where('id', $egg->id)->update([
'docker_images' => array_values(json_decode($egg->docker_images, true, 512, JSON_THROW_ON_ERROR)),
]);
});
}
}