<?php declare(strict_types=1);

namespace Atl\DiscountExtension\Migration;

use Doctrine\DBAL\Connection;
use Shopware\Core\Framework\Migration\MigrationStep;

class Migration1645524148SpwnRepeatDiscount extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1645524148;
    }

    public function update(Connection $connection): void
    {
        $connection->executeStatement('
          CREATE TABLE IF NOT EXISTS `spwn_repeat_discount` (
          `id` BINARY(16) NOT NULL,
          `customer_id` BINARY(16) NOT NULL,
          `last_order_date` DATETIME(3) NOT NULL,
          `created_at`  DATETIME(3) NOT NULL,
          `updated_at`  DATETIME(3) NULL,
          PRIMARY KEY (`id`),
          CONSTRAINT `uniq.spwn_repeat_discount.customer_id` UNIQUE (`customer_id`),
          CONSTRAINT `fk.spwn_repeat_discount.customer_id` FOREIGN KEY (`customer_id`)
            REFERENCES `customer` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
        ');
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive
    }
}
