<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('chapters', function (Blueprint $table) {
            $table->unsignedBigInteger('cooperative_id')->nullable()->after('name');
            $table->foreign('cooperative_id')->references('id')->on('organizations')->nullOnDelete();
            $table->index('cooperative_id');
        });
    }

    public function down(): void
    {
        Schema::table('chapters', function (Blueprint $table) {
            $table->dropForeign(['cooperative_id']);
            $table->dropIndex(['cooperative_id']);
            $table->dropColumn('cooperative_id');
        });
    }
};
