<?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
    {
        // 重命名 raw_hash 为 hash
        Schema::getConnection()->statement('ALTER TABLE orders RENAME COLUMN raw_hash TO hash');

        // 将 raw 和 hash 改为非空
        Schema::getConnection()->statement('ALTER TABLE orders ALTER COLUMN raw SET NOT NULL');
        Schema::getConnection()->statement('ALTER TABLE orders ALTER COLUMN hash SET NOT NULL');
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // 将 raw 和 hash 改回可空
        Schema::getConnection()->statement('ALTER TABLE orders ALTER COLUMN raw DROP NOT NULL');
        Schema::getConnection()->statement('ALTER TABLE orders ALTER COLUMN hash DROP NOT NULL');

        // 重命名 hash 回 raw_hash
        Schema::getConnection()->statement('ALTER TABLE orders RENAME COLUMN hash TO raw_hash');
    }
};
