-- Migrate existing ignored entries from qt_vendor_partnumber_seen to qt_ignore_rules.
-- Rows with is_ignored=1 and is_pattern=0 become exact partnumber rules.
-- Rows with is_ignored=1 and is_pattern=1 become glob partnumber rules.
INSERT IGNORE INTO qt_ignore_rules (field, match_type, pattern, note, created_by)
SELECT
    'partnumber',
    CASE WHEN is_pattern = 1 THEN 'glob' ELSE 'exact' END,
    partnumber,
    CONCAT('Migrated from qt_vendor_partnumber_seen id=', id),
    COALESCE(ignored_by, 'migration')
FROM qt_vendor_partnumber_seen
WHERE is_ignored = 1;
