-- MIGRACJA: Tabela domowien od zintegrowanych dostawcow

CREATE TABLE IF NOT EXISTS `shop_supplement_order` (
    `id`            INT UNSIGNED    NOT NULL AUTO_INCREMENT,
    `id_shop`       INT UNSIGNED    NOT NULL,
    `order_key`     VARCHAR(128)    NOT NULL,
    `reference`     VARCHAR(128)    NULL,
    `supplier_name` VARCHAR(255)    NOT NULL,
    `order_date`    DATE            NOT NULL,
    `expected_date` DATE            NULL,
    `products_json` JSON            NOT NULL,
    `status`        ENUM('NEW','ARCHIVED') NOT NULL DEFAULT 'NEW',
    `created_at`    TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`    TIMESTAMP       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_shop_order_key` (`id_shop`, `order_key`),
    INDEX `idx_id_shop_status` (`id_shop`, `status`),
    INDEX `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
