DELETE FROM address WHERE legacyId IS NOT NULL;

INSERT INTO raktar24.address (
    legacyId,
    createdAt,
    countryId,
    zipCode,
    city,
    district,
    address
)

SELECT
    t.tid AS legacyId,
    CURRENT_TIMESTAMP AS createdAt,
    17 AS countryId,
    CASE t.tid
        WHEN 1 THEN '2000'
        WHEN 2 THEN '2113'
        WHEN 3 THEN '2000'
        WHEN 4 THEN '1038'
        WHEN 5 THEN '1035'
        WHEN 89 THEN '2134'
        WHEN 92 THEN '4096'
        WHEN 98 THEN '2000'
        WHEN 102 THEN '1074'
        WHEN 106 THEN '2013'
        WHEN 108 THEN '9086'
        WHEN 116 THEN '1134'
        WHEN 121 THEN '1086'
        WHEN 127 THEN '1139'
        WHEN 137 THEN '1032'
        ELSE ''
    END AS zipCode,
    TRIM( SUBSTRING_INDEX( t.name, ',', 1 ) ) AS city,
    CASE t.tid
        WHEN 4 THEN 'III. kerület'
        WHEN 5 THEN 'III. kerület'
        WHEN 102 THEN 'VII. kerület'
        WHEN 116 THEN 'XIII. kerület'
        WHEN 121 THEN 'VIII. kerület'
        WHEN 127 THEN 'XIII. kerület'
        WHEN 137 THEN 'III. kerület'
        ELSE ''
    END AS district,
    TRIM( SUBSTRING_INDEX( t.name, ',', -1 ) ) AS address
FROM raktar24_old.taxonomy_term_data AS t
WHERE t.vid = 2;