<?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_family_members', function (Blueprint $table) {
            $table->id();
            $table->foreignId('family_id')->constrained('account_families')->onDelete('cascade')->comment('家庭ID');
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->foreign('user_id')->references('uid')->on('member')->onDelete('cascade');
            $table->timestamps();

            $table->index('family_id');
            $table->index('user_id');
            $table->unique(['family_id', 'user_id']);
        });
    }

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