Files
BMS/bms-back/sql/price/product_country_expire_alter.sql
T
2026-09-08 10:51:20 +08:00

15 lines
744 B
SQL

-- 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);