<?php

declare(strict_types=1);

namespace Plugin\cin_quick_purchase_5\Migrations;

use JTL\Plugin\Migration;
use JTL\Update\IMigration;

final class Migration20260309095207 extends Migration implements IMigration
{
  public function up(): void
  {
    $this->execute('CREATE TABLE IF NOT EXISTS `xplugin_cin_quick_purchase_5_tmp` (
      `kArtikel` INT UNSIGNED NOT NULL,
      `anzahl_versuche` INT NOT NULL DEFAULT 0
    ) ENGINE = InnoDB;');

    $this->execute('ALTER TABLE `xplugin_cin_quick_purchase_5_tmp` ADD UNIQUE(`kArtikel`);');
  }

  public function down(): void
  {
    if ($this->doDeleteData()) {
      $this->execute('DROP TABLE IF EXISTS `xplugin_cin_quick_purchase_5_tmp`');
    }
  }
}
