# noinspection SpellCheckingInspectionForFile

DELETE FROM storage_property_option WHERE legacyId IS NOT NULL;

INSERT INTO storage_property_option (
    legacyId,
    orderNumber,
    createdAt,
    name,
    storagePropertyId
)

SELECT
    ttd.tid AS legacyId,
    ttd.weight AS orderNumber,
    sp.createdAt AS createdAt,
    ttd.name AS name,
    sp.id AS storagePropertyId
FROM raktar24_old.taxonomy_term_data AS ttd
LEFT JOIN raktar24_old.taxonomy_vocabulary AS tv ON tv.vid = ttd.vid
LEFT JOIN raktar24_old.field_config AS fc ON fc.field_name = CONCAT( 'field_', ( CASE tv.machine_name
    WHEN 'eljutas' THEN 'epulethez'
    WHEN 'belog_targy' THEN 'belogo'
    WHEN 'zar' THEN 'zartipusa'
    ELSE tv.machine_name
END ) )
LEFT JOIN storage_property AS sp ON sp.legacyField = fc.field_name
WHERE sp.type IN ( 'SELECT', 'MULTISELECT' );