<?php

declare(strict_types=1);

namespace Plugin\cin_ajax_search_5\Migrations;

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

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

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