id(); $table->foreignId('world_id')->constrained()->cascadeOnDelete(); $table->string('name', 32); $table->string('tag', 6); $table->text('description')->nullable(); $table->timestamps(); $table->unique(['world_id', 'name']); $table->unique(['world_id', 'tag']); }); Schema::create('tribe_members', function (Blueprint $table) { $table->id(); $table->foreignId('tribe_id')->constrained()->cascadeOnDelete(); // A player belongs to one tribe at most. $table->foreignId('player_id')->unique()->constrained()->cascadeOnDelete(); $table->string('role', 16); $table->timestamps(); }); Schema::create('tribe_invites', function (Blueprint $table) { $table->id(); $table->foreignId('tribe_id')->constrained()->cascadeOnDelete(); $table->foreignId('player_id')->constrained()->cascadeOnDelete(); $table->foreignId('invited_by')->nullable()->constrained('players')->nullOnDelete(); $table->timestamps(); $table->unique(['tribe_id', 'player_id']); }); // One row per direction: what tribe_id holds towards other_tribe_id. An alliance or // NAP counts once both rows are confirmed; ends_at is the end of its notice period. Schema::create('tribe_relations', function (Blueprint $table) { $table->id(); $table->foreignId('tribe_id')->constrained()->cascadeOnDelete(); $table->foreignId('other_tribe_id')->constrained('tribes')->cascadeOnDelete(); $table->string('state', 8); $table->dateTime('confirmed_at', 3)->nullable(); $table->dateTime('ends_at', 3)->nullable(); $table->timestamps(); $table->unique(['tribe_id', 'other_tribe_id']); }); Schema::create('tribe_events', function (Blueprint $table) { $table->id(); $table->foreignId('tribe_id')->constrained()->cascadeOnDelete(); $table->string('type', 32); $table->json('payload'); $table->dateTime('happened_at', 3); $table->index(['tribe_id', 'happened_at']); }); } public function down(): void { Schema::dropIfExists('tribe_events'); Schema::dropIfExists('tribe_relations'); Schema::dropIfExists('tribe_invites'); Schema::dropIfExists('tribe_members'); Schema::dropIfExists('tribes'); } };