<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        // 파티셔닝된 테이블에 컬럼 추가
        DB::statement("
            ALTER TABLE trigger_audit_logs
            ADD COLUMN operation_id VARCHAR(36) DEFAULT NULL COMMENT '작업 단위 ID (요청별 UUID)' AFTER session_info
        ");

        // operation_id 인덱스 (일괄 롤백 조회용)
        DB::statement("
            CREATE INDEX ix_trig_operation
                ON trigger_audit_logs (operation_id, created_at)
        ");
    }

    public function down(): void
    {
        DB::statement('DROP INDEX ix_trig_operation ON trigger_audit_logs');
        DB::statement('ALTER TABLE trigger_audit_logs DROP COLUMN operation_id');
    }
};