<?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::table('platforms', function (Blueprint $table) {
            $table->unsignedBigInteger('developer_id')->default(1)->comment('数据维护者，关联 users.id');
            $table->foreign('developer_id')->references('id')->on('users')->onDelete('restrict');
            $table->index('developer_id', 'idx_platforms_developer_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('platforms', function (Blueprint $table) {
            $table->dropForeign(['developer_id']);
            $table->dropIndex('idx_platforms_developer_id');
            $table->dropColumn('developer_id');
        });
    }
};
