game-village-politics-backend/database/migrations/2026_10_29_120000_create_mi...

46 lines
1.7 KiB
PHP
Raw Permalink Normal View History

<?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
{
// Troops by where they stand and whose they are (support is M4).
Schema::create('unit_stacks', function (Blueprint $table) {
$table->id();
$table->foreignId('village_id')->constrained()->cascadeOnDelete();
$table->foreignId('home_village_id')->constrained('villages')->cascadeOnDelete();
$table->string('unit', 32);
$table->unsignedInteger('count')->default(0);
$table->timestamps();
$table->unique(['village_id', 'home_village_id', 'unit']);
});
// One queue per military building instance. Times are fixed when queued, so units
// arrive lazily: done = floor((now − starts_at) / seconds_per_unit).
Schema::create('recruit_orders', function (Blueprint $table) {
$table->id();
$table->foreignId('village_id')->constrained()->cascadeOnDelete();
$table->foreignId('building_id')->constrained()->cascadeOnDelete();
$table->string('unit', 32);
$table->unsignedInteger('count');
$table->unsignedInteger('done')->default(0);
$table->unsignedInteger('seconds_per_unit');
// Per unit, refunded for the ones not trained when cancelled.
$table->json('cost');
$table->dateTime('starts_at', 3);
$table->dateTime('finishes_at', 3);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('recruit_orders');
Schema::dropIfExists('unit_stacks');
}
};