-- 扩展既有设备导入任务，承载单列 CSV 批量分配代理或套餐系列。
ALTER TABLE tb_device_import_task
    ADD COLUMN IF NOT EXISTS operation_type VARCHAR(32) NOT NULL DEFAULT 'import',
    ADD COLUMN IF NOT EXISTS target_id BIGINT,
    ADD COLUMN IF NOT EXISTS operator_type INT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS operator_shop_id BIGINT;

CREATE INDEX IF NOT EXISTS idx_device_import_task_operation_type
    ON tb_device_import_task(operation_type, created_at DESC)
    WHERE deleted_at IS NULL;

COMMENT ON COLUMN tb_device_import_task.operation_type IS '任务业务类型(import=导入设备,assign_shop=分配目标代理,assign_series=设置套餐系列)';
COMMENT ON COLUMN tb_device_import_task.target_id IS '批量分配目标店铺或套餐系列ID';
COMMENT ON COLUMN tb_device_import_task.operator_type IS '任务创建时操作者类型快照';
COMMENT ON COLUMN tb_device_import_task.operator_shop_id IS '任务创建时操作者店铺ID快照';
