-- liquibase formatted sql
-- changeset 2fi:20260507_01_truck_lane_version_line_add_logisticId
-- preconditions onFail:MARK_RAN
-- precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'truck_lane_version_line' AND column_name = 'logisticId'

SET @col_tlvl_lid := (
    SELECT COUNT(*)
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name = 'truck_lane_version_line'
      AND column_name = 'logisticId'
);
SET @sql_add_tlvl_lid := IF(
    @col_tlvl_lid = 0,
    'ALTER TABLE `truck_lane_version_line` ADD COLUMN `logisticId` BIGINT NULL DEFAULT NULL AFTER `remark`',
    'SELECT 1'
);
PREPARE stmt_add_tlvl_lid FROM @sql_add_tlvl_lid;
EXECUTE stmt_add_tlvl_lid;
DEALLOCATE PREPARE stmt_add_tlvl_lid;

SET @idx_tlvl_lid := (
    SELECT COUNT(*)
    FROM information_schema.statistics
    WHERE table_schema = DATABASE()
      AND table_name = 'truck_lane_version_line'
      AND index_name = 'idx_tlvl_logisticId'
);
SET @sql_tlvl_lid := IF(
    @idx_tlvl_lid = 0,
    'CREATE INDEX idx_tlvl_logisticId ON `truck_lane_version_line` (`logisticId`)',
    'SELECT 1'
);
PREPARE stmt_tlvl_lid FROM @sql_tlvl_lid;
EXECUTE stmt_tlvl_lid;
DEALLOCATE PREPARE stmt_tlvl_lid;

