diff --git a/src/main/resources/db/migration/V4__Country.sql b/src/main/resources/db/migration/V4__Country.sql index e3806f5..5e0d4c1 100644 --- a/src/main/resources/db/migration/V4__Country.sql +++ b/src/main/resources/db/migration/V4__Country.sql @@ -581,7 +581,7 @@ SELECT FROM `country` c, `country_property_type` cpt WHERE cpt.external_mapping_id = 'SAFETY_STOCK'; --- Air Freight Share Properties (all countries have 0%) +-- Air Freight Share Properties (0.03 for countries with safety stock 55, otherwise 0%) INSERT INTO `country_property` (`country_id`, `country_property_type_id`, `property_set_id`, `property_value`) SELECT @@ -593,8 +593,26 @@ SELECT AND (ps.end_date IS NULL OR ps.end_date > NOW()) ORDER BY ps.start_date DESC LIMIT 1), - '0' -FROM `country` c, `country_property_type` cpt + CASE + WHEN cp_safety.property_value = '55' THEN '0.03' + ELSE '0' + END +FROM `country` c + CROSS JOIN `country_property_type` cpt + LEFT JOIN `country_property` cp_safety + ON cp_safety.country_id = c.id + AND cp_safety.country_property_type_id = ( + SELECT id FROM `country_property_type` + WHERE external_mapping_id = 'SAFETY_STOCK' + ) + AND cp_safety.property_set_id = ( + SELECT ps.id FROM `property_set` ps + WHERE ps.state = 'VALID' + AND ps.start_date <= NOW() + AND (ps.end_date IS NULL OR ps.end_date > NOW()) + ORDER BY ps.start_date DESC + LIMIT 1 + ) WHERE cpt.external_mapping_id = 'AIR_SHARE'; -- Wage Factor Properties (only for countries with defined values)