<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('user_data_scopes', function (Blueprint $table) {
            $table->id()->comment('主键');
            $table->unsignedBigInteger('user_id')->comment('用户 ID');
            $table->string('scope_type', 20)->comment('范围类型: company/platform/store');
            $table->unsignedBigInteger('scope_id')->comment('范围目标 ID');
            $table->timestampTz('created_at')->useCurrent()->comment('创建时间');

            $table->unique(['user_id', 'scope_type', 'scope_id']);
            $table->index('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }

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