-- =============================================================
-- COMPENSATING MIGRATION
-- Kompensuje: 20260302_000020_create_order_status_mappings_table.sql
-- Powód: Oryginalna migracja 000020 zawiera identyczne CREATE TABLE IF NOT EXISTS,
--        ale nie dotarła do środowiska produkcyjnego (niepełna historia migracji).
--        Migracja 000038 jest bezpiecznym powtórzeniem — idempotentna dzięki IF NOT EXISTS.
-- Status: Środowisko zsynchronizowane po 2026-03-08. Migracja
--         idempotentna — bezpieczna do ponownego uruchomienia.
-- =============================================================
CREATE TABLE IF NOT EXISTS order_status_mappings (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    integration_id INT UNSIGNED NOT NULL,
    shoppro_status_code VARCHAR(64) NOT NULL,
    shoppro_status_name VARCHAR(128) NULL,
    orderpro_status_code VARCHAR(64) NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY order_status_mappings_integration_shoppro_unique (integration_id, shoppro_status_code),
    KEY order_status_mappings_integration_idx (integration_id),
    KEY order_status_mappings_orderpro_idx (orderpro_status_code),
    CONSTRAINT order_status_mappings_integration_fk
        FOREIGN KEY (integration_id) REFERENCES integrations(id)
        ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
