<?php

declare(strict_types=1);

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

class AddCompoundIndexToPosTransactions extends Migration
{
    public function up(): void
    {
        Schema::table('pos_transactions', function (Blueprint $table) {
            // Compound index for the updateOrCreate lookup pattern used in PosController::addItem
            $table->index(['pos_session_id', 'product_id'], 'pos_tx_session_product_idx');
        });
    }

    public function down(): void
    {
        Schema::table('pos_transactions', function (Blueprint $table) {
            $table->dropIndex('pos_tx_session_product_idx');
        });
    }
}
