52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
// ---------------------------------------------------------------
|
|
// GUILDS
|
|
// ---------------------------------------------------------------
|
|
Schema::create('guilds', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('owner_id')->constrained('users')->cascadeOnDelete();
|
|
$table->string('name', 64)->unique();
|
|
$table->string('tag', 6)->unique();
|
|
$table->string('logo_url')->nullable();
|
|
$table->string('invite_code', 16)->unique();
|
|
$table->string('description', 500)->nullable();
|
|
$table->unsignedInteger('points')->default(0);
|
|
$table->unsignedInteger('members_count')->default(0);
|
|
$table->timestamps();
|
|
|
|
$table->index(['owner_id']);
|
|
$table->index(['points', 'members_count']);
|
|
});
|
|
|
|
// ---------------------------------------------------------------
|
|
// GUILD MEMBERS
|
|
// ---------------------------------------------------------------
|
|
Schema::create('guild_members', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('guild_id')->constrained('guilds')->cascadeOnDelete();
|
|
$table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
|
|
$table->string('role', 16)->default('member'); // owner | officer | member
|
|
$table->timestamp('joined_at')->nullable();
|
|
$table->timestamps();
|
|
|
|
$table->unique(['guild_id', 'user_id']);
|
|
$table->index('user_id');
|
|
});
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('guild_members');
|
|
Schema::dropIfExists('guilds');
|
|
}
|
|
};
|