2020-09-06 23:50:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Engelsystem\Migrations;
|
|
|
|
|
|
|
|
use Engelsystem\Database\Migration\Migration;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
|
use stdClass;
|
|
|
|
|
|
|
|
class CreateRoomsTable extends Migration
|
|
|
|
{
|
|
|
|
use ChangesReferences;
|
|
|
|
use Reference;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the migration
|
|
|
|
*/
|
|
|
|
public function up(): void
|
|
|
|
{
|
2022-12-14 19:15:20 +01:00
|
|
|
$this->schema->create('rooms', function (Blueprint $table): void {
|
2020-09-06 23:50:36 +02:00
|
|
|
$table->increments('id');
|
|
|
|
$table->string('name', 35)->unique();
|
|
|
|
$table->string('map_url', 300)->nullable();
|
|
|
|
$table->text('description')->nullable();
|
|
|
|
$table->timestamps();
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($this->schema->hasTable('Room')) {
|
|
|
|
$connection = $this->schema->getConnection();
|
|
|
|
/** @var stdClass[] $previousRecords */
|
|
|
|
$previousRecords = $connection
|
|
|
|
->table('Room')
|
|
|
|
->get();
|
|
|
|
|
|
|
|
foreach ($previousRecords as $previousRecord) {
|
2022-10-21 15:40:14 +02:00
|
|
|
$connection->table('rooms')
|
|
|
|
->insert([
|
|
|
|
'id' => $previousRecord->RID,
|
|
|
|
'name' => $previousRecord->Name,
|
|
|
|
'map_url' => $previousRecord->map_url ?: null,
|
|
|
|
'description' => $previousRecord->description ?: null,
|
|
|
|
]);
|
2020-09-06 23:50:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->changeReferences(
|
|
|
|
'Room',
|
|
|
|
'RID',
|
|
|
|
'rooms',
|
|
|
|
'id'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->schema->drop('Room');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reverse the migration
|
|
|
|
*/
|
|
|
|
public function down(): void
|
|
|
|
{
|
2022-10-21 15:40:14 +02:00
|
|
|
$connection = $this->schema->getConnection();
|
|
|
|
|
2022-12-14 19:15:20 +01:00
|
|
|
$this->schema->create('Room', function (Blueprint $table): void {
|
2020-09-06 23:50:36 +02:00
|
|
|
$table->increments('RID');
|
|
|
|
$table->string('Name', 35)->unique();
|
|
|
|
$table->string('map_url', 300)->nullable();
|
|
|
|
$table->mediumText('description')->nullable();
|
|
|
|
});
|
|
|
|
|
2022-10-21 15:40:14 +02:00
|
|
|
foreach ($connection->table('rooms')->get() as $room) {
|
|
|
|
/** @var stdClass $room */
|
|
|
|
$connection
|
2020-09-06 23:50:36 +02:00
|
|
|
->table('Room')
|
|
|
|
->insert([
|
|
|
|
'RID' => $room->id,
|
|
|
|
'Name' => $room->name,
|
|
|
|
'map_url' => $room->map_url ?: null,
|
|
|
|
'description' => $room->description ?: null,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->changeReferences(
|
|
|
|
'rooms',
|
|
|
|
'id',
|
|
|
|
'Room',
|
|
|
|
'RID'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->schema->drop('rooms');
|
|
|
|
}
|
|
|
|
}
|