-- Migration 0021: case-insensitive identifiers
--
-- Per identifier-normalization contract: original values are stored as-is,
-- all comparisons (including UNIQUE constraints) are case-insensitive.
--
-- WARNING: if the database already contains rows that differ only in case
-- (e.g. "SN-001" and "sn-001") this migration will fail with a duplicate-key
-- error. Deduplicate the data first.
--
-- We use utf8mb4_unicode_ci which is case-insensitive and accent-insensitive.

-- ── parts ────────────────────────────────────────────────────────────────────
ALTER TABLE parts
    MODIFY vendor_serial    VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
    MODIFY vendor           VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
    MODIFY model            VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
    MODIFY firmware_version VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
    MODIFY component_type   VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL;

-- ── machines ─────────────────────────────────────────────────────────────────
ALTER TABLE machines
    MODIFY vendor_serial    VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
    MODIFY vendor           VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
    MODIFY model            VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
    MODIFY cpu_model        VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL;

-- ── observations ─────────────────────────────────────────────────────────────
ALTER TABLE observations
    MODIFY firmware_version VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL;

-- ── machine_firmware_states ───────────────────────────────────────────────────
ALTER TABLE machine_firmware_states
    MODIFY device_name      VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
    MODIFY firmware_version VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;
