Set up proposed DB schema
This commit is contained in:
parent
1414b2c65d
commit
14f55868fc
36
app/FreeCompanyLink.php
Normal file
36
app/FreeCompanyLink.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class FreeCompanyLink extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'freeCompanyId',
|
||||||
|
'discordGuildId',
|
||||||
|
'domainName'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function freeCompanyMembers()
|
||||||
|
{
|
||||||
|
return $this->hasMany(FreeCompanyMember::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function freeCompanyRanks()
|
||||||
|
{
|
||||||
|
return $this->hasMany(FreeCompanyRank::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function linkCodes()
|
||||||
|
{
|
||||||
|
return $this->hasMany(LinkCode::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function userLinks()
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserLink::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/FreeCompanyMember.php
Normal file
19
app/FreeCompanyMember.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class FreeCompanyMember extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'freeCompanyLinkId',
|
||||||
|
'lodestoneId',
|
||||||
|
'lastSeenRank'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function freeCompanyLink()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(FreeCompanyLink::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/FreeCompanyRank.php
Normal file
23
app/FreeCompanyRank.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class FreeCompanyRank extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'rankName',
|
||||||
|
'freeCompanyLinkId',
|
||||||
|
'daysRequired',
|
||||||
|
'discordRoleId',
|
||||||
|
'websiteRole'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function freeCompanyLink()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(FreeCompanyLink::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
}
|
||||||
28
app/LinkCode.php
Normal file
28
app/LinkCode.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class LinkCode extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'freeCompanyLinkId',
|
||||||
|
'lodestoneId',
|
||||||
|
'discordUserId',
|
||||||
|
'websiteUserId',
|
||||||
|
'expires',
|
||||||
|
'code'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'expires' => 'datetime'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function freeCompanyLink()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(FreeCompanyLink::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/LodestoneCache.php
Normal file
16
app/LodestoneCache.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class LodestoneCache extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'type',
|
||||||
|
'lodestoneId',
|
||||||
|
'content'
|
||||||
|
];
|
||||||
|
}
|
||||||
20
app/UserLink.php
Normal file
20
app/UserLink.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class UserLink extends Model
|
||||||
|
{
|
||||||
|
protected $fillable = [
|
||||||
|
'freeCompanyLinkId',
|
||||||
|
'lodestoneId',
|
||||||
|
'discordUserId',
|
||||||
|
'websiteUserId'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function freeCompanyLink()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(FreeCompanyLink::class, 'freeCompanyLinkId');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateFreeCompanyLinksTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('free_company_links', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->bigInteger('freeCompanyId')->unique();
|
||||||
|
$table->bigInteger('discordGuildId')->nullable();
|
||||||
|
$table->string('domainName', 255)->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('free_company_links');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateLinkCodesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('link_codes', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('freeCompanyLinkId')->constrained('free_company_links');
|
||||||
|
$table->bigInteger('lodestoneId');
|
||||||
|
$table->bigInteger('discordUserId')->nullable();
|
||||||
|
$table->bigInteger('websiteUserId')->nullable();
|
||||||
|
$table->dateTime('expires');
|
||||||
|
$table->string('code', 128);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('link_codes');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateUserLinksTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('user_links', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('freeCompanyLinkId')->constrained('free_company_links');
|
||||||
|
$table->bigInteger('lodestoneId')->nullable();
|
||||||
|
$table->bigInteger('discordUserId')->nullable();
|
||||||
|
$table->bigInteger('websiteUserId')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('user_links');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateLodestoneCachesTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('lodestone_caches', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->integer('type');
|
||||||
|
$table->bigInteger('lodestoneId');
|
||||||
|
$table->text('content');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['type', 'lodestoneId']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('lodestone_caches');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateFreeCompanyMembersTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('free_company_members', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('freeCompanyLinkId')->constrained('free_company_links');
|
||||||
|
$table->bigInteger('lodestoneId');
|
||||||
|
$table->string('lastSeenRank', 64);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('free_company_members');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateFreeCompanyRanksTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('free_company_ranks', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('rankName', 64);
|
||||||
|
$table->foreignId('freeCompanyLinkId')->constrained('free_company_links');
|
||||||
|
$table->integer('daysRequired');
|
||||||
|
$table->bigInteger('discordRoleId')->nullable();
|
||||||
|
$table->string('websiteRole', 64)->nullable();
|
||||||
|
|
||||||
|
$table->unique(['rankName', 'freeCompanyLinkId']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('free_company_ranks');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testBasicTest()
|
|
||||||
{
|
|
||||||
$response = $this->get('/');
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A basic test example.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testBasicTest()
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
77
tests/Unit/RelationTest.php
Normal file
77
tests/Unit/RelationTest.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\FreeCompanyLink;
|
||||||
|
use App\FreeCompanyMember;
|
||||||
|
use App\FreeCompanyRank;
|
||||||
|
use App\LinkCode;
|
||||||
|
use App\UserLink;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class RelationTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A basic unit test example.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCanFetchRelations()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
$fcLink = FreeCompanyLink::create([
|
||||||
|
'freeCompanyId' => 1,
|
||||||
|
'discordGuildId' => 1,
|
||||||
|
'domainName' => 'example.com'
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
$userLink = UserLink::create([
|
||||||
|
'freeCompanyLinkId' => $fcLink->id,
|
||||||
|
'lodestoneId' => 1,
|
||||||
|
'discordUserId' => 1,
|
||||||
|
'websiteUserId' => 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
$linkCode = LinkCode::create([
|
||||||
|
'freeCompanyLinkId' => $fcLink->id,
|
||||||
|
'lodestoneId' => 1,
|
||||||
|
'discordUserId' => 1,
|
||||||
|
'websiteId' => 1,
|
||||||
|
'expires' => Carbon::now(),
|
||||||
|
'code' => 'asdf'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fcMember = FreeCompanyMember::create([
|
||||||
|
'freeCompanyLinkId' => $fcLink->id,
|
||||||
|
'lodestoneId' => 1,
|
||||||
|
'lastSeenRank' => 'Mentor'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fcRank = FreeCompanyRank::create([
|
||||||
|
'rankName' => 'asdf',
|
||||||
|
'freeCompanyLinkId' => $fcLink->id,
|
||||||
|
'daysRequired' => 2,
|
||||||
|
'websiteRole' => 'asdf'
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
$this->assertEquals($userLink->freeCompanyLink->id, $fcLink->id);
|
||||||
|
$this->assertEquals($linkCode->freeCompanyLink->id, $fcLink->id);
|
||||||
|
$this->assertEquals($fcMember->freeCompanyLink->id, $fcLink->id);
|
||||||
|
$this->assertEquals($fcRank->freeCompanyLink->id, $fcLink->id);
|
||||||
|
|
||||||
|
$this->assertEquals($userLink->id, $fcLink->userLinks->first()->id);
|
||||||
|
$this->assertEquals($linkCode->id, $fcLink->linkCodes->first()->id);
|
||||||
|
$this->assertEquals($fcMember->id, $fcLink->freeCompanyMembers->first()->id);
|
||||||
|
$this->assertEquals($fcRank->id, $fcLink->freeCompanyRanks->first()->id);
|
||||||
|
|
||||||
|
// Abrogate
|
||||||
|
$fcMember->delete();
|
||||||
|
$fcRank->delete();
|
||||||
|
$linkCode->delete();
|
||||||
|
$userLink->delete();
|
||||||
|
$fcLink->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user