Added Room model
parent
8296ef0662
commit
acf84f222d
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Engelsystem\Migrations;
|
||||
|
||||
use Engelsystem\Database\Migration\Migration;
|
||||
use Engelsystem\Models\Room;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use stdClass;
|
||||
|
||||
class CreateRoomsTable extends Migration
|
||||
{
|
||||
use ChangesReferences;
|
||||
use Reference;
|
||||
|
||||
/**
|
||||
* Run the migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->schema->create('rooms', function (Blueprint $table) {
|
||||
$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) {
|
||||
$room = new Room([
|
||||
'name' => $previousRecord->Name,
|
||||
'map_url' => $previousRecord->map_url ?: null,
|
||||
'description' => $previousRecord->description ?: null,
|
||||
]);
|
||||
$room->setAttribute('id', $previousRecord->RID);
|
||||
$room->save();
|
||||
}
|
||||
|
||||
$this->changeReferences(
|
||||
'Room',
|
||||
'RID',
|
||||
'rooms',
|
||||
'id'
|
||||
);
|
||||
|
||||
$this->schema->drop('Room');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$this->schema->create('Room', function (Blueprint $table) {
|
||||
$table->increments('RID');
|
||||
$table->string('Name', 35)->unique();
|
||||
$table->string('map_url', 300)->nullable();
|
||||
$table->mediumText('description')->nullable();
|
||||
});
|
||||
|
||||
foreach (Room::all() as $room) {
|
||||
$this->schema
|
||||
->getConnection()
|
||||
->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');
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Engelsystem\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Query\Builder as QueryBuilder;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $map_url
|
||||
* @property string $description
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
*
|
||||
* @method static QueryBuilder|Room[] whereId($value)
|
||||
* @method static QueryBuilder|Room[] whereName($value)
|
||||
* @method static QueryBuilder|Room[] whereMapUrl($value)
|
||||
* @method static QueryBuilder|Room[] whereDescription($value)
|
||||
* @method static QueryBuilder|Room[] whereCreatedAt($value)
|
||||
* @method static QueryBuilder|Room[] whereUpdatedAt($value)
|
||||
*/
|
||||
class Room extends BaseModel
|
||||
{
|
||||
/** @var bool Enable timestamps */
|
||||
public $timestamps = true;
|
||||
|
||||
/** @var array */
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'map_url',
|
||||
'description',
|
||||
];
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Engelsystem\Test\Feature\Model;
|
||||
|
||||
use Engelsystem\Test\Feature\ApplicationFeatureTest;
|
||||
|
||||
class RoomModelTest extends ApplicationFeatureTest
|
||||
{
|
||||
/** @var int */
|
||||
private $room_id = null;
|
||||
|
||||
/**
|
||||
* @covers \Room_create
|
||||
*/
|
||||
public function createRoom()
|
||||
{
|
||||
$this->room_id = Room_create('test', null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Room
|
||||
*/
|
||||
public function testRoom()
|
||||
{
|
||||
$this->createRoom();
|
||||
|
||||
$room = Room($this->room_id);
|
||||
|
||||
$this->assertNotEmpty($room);
|
||||
$this->assertNotNull($room);
|
||||
$this->assertEquals('test', $room['Name']);
|
||||
|
||||
$this->assertEmpty(Room(-1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->room_id != null) {
|
||||
Room_delete($this->room_id);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue