<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('account_families', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('家庭名称');
            $table->unsignedBigInteger('owner_id')->comment('家主用户ID');
            $table->foreign('owner_id')->references('uid')->on('member')->onDelete('cascade');
            $table->string('invite_code', 10)->unique()->comment('邀请码');
            $table->timestamps();
            $table->softDeletes();

            $table->index('owner_id');
            $table->index('invite_code');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('account_families');
    }
};
