-- Add expire_date for product country versioning on re-import -- When new effective_date is later than previous, keep old rows and set their expire_date = new effective_date SET NAMES utf8mb4; ALTER TABLE bms_product_country ADD COLUMN expire_date date DEFAULT NULL COMMENT 'expire date (null=open; set to next import effective_date)' AFTER effective_date; -- Allow multiple versions: unique includes effective_date ALTER TABLE bms_product_country DROP INDEX uk_product_country_weight; ALTER TABLE bms_product_country ADD UNIQUE KEY uk_product_country_weight_eff (product_code, country_name, weight_min, weight_max, effective_date); ALTER TABLE bms_product_country ADD KEY idx_product_eff (product_code, effective_date, expire_date);