CREATE TABLE storefront_cart_states (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    shop_id BIGINT UNSIGNED NOT NULL,
    user_id BIGINT UNSIGNED NOT NULL,
    payload_json JSON NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uniq_storefront_cart_states_shop_user (shop_id, user_id),
    INDEX idx_storefront_cart_states_user (user_id),
    CONSTRAINT fk_storefront_cart_states_shop FOREIGN KEY (shop_id) REFERENCES shops(id),
    CONSTRAINT fk_storefront_cart_states_user FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE storefront_checkout_states (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    shop_id BIGINT UNSIGNED NOT NULL,
    user_id BIGINT UNSIGNED NOT NULL,
    payload_json JSON NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uniq_storefront_checkout_states_shop_user (shop_id, user_id),
    INDEX idx_storefront_checkout_states_user (user_id),
    CONSTRAINT fk_storefront_checkout_states_shop FOREIGN KEY (shop_id) REFERENCES shops(id),
    CONSTRAINT fk_storefront_checkout_states_user FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
