ALTER TABLE shop_products
    ADD COLUMN inherit_name TINYINT NOT NULL DEFAULT 1 AFTER is_visible,
    ADD COLUMN inherit_description TINYINT NOT NULL DEFAULT 1 AFTER inherit_name,
    ADD COLUMN inherit_specs TINYINT NOT NULL DEFAULT 1 AFTER inherit_description,
    ADD COLUMN inherit_image TINYINT NOT NULL DEFAULT 1 AFTER inherit_specs;

UPDATE shop_products
SET
    inherit_name = CASE
        WHEN override_name IS NULL OR override_name = '' THEN 1
        ELSE 0
    END,
    inherit_description = CASE
        WHEN override_description IS NULL OR override_description = '' THEN 1
        ELSE 0
    END,
    inherit_specs = CASE
        WHEN override_spec_json IS NULL OR TRIM(CAST(override_spec_json AS CHAR)) = '' OR TRIM(CAST(override_spec_json AS CHAR)) = '{}' THEN 1
        ELSE 0
    END,
    inherit_image = CASE
        WHEN EXISTS (
            SELECT 1
            FROM shop_product_assets spa
            WHERE spa.shop_product_id = shop_products.id
        ) THEN 0
        ELSE 1
    END;
