-- 小程序 VIN 车辆绑定字段(app_user_id)
|
-- 说明:绑定列统一命名为 app_user_id,脚本幂等可重复执行
|
|
SET @column_exists := (
|
SELECT COUNT(1)
|
FROM information_schema.COLUMNS
|
WHERE TABLE_SCHEMA = DATABASE()
|
AND TABLE_NAME = 't_vin_management'
|
AND COLUMN_NAME = 'app_user_id'
|
);
|
SET @column_sql := IF(
|
@column_exists = 0,
|
'ALTER TABLE `t_vin_management` ADD COLUMN `app_user_id` BIGINT NULL COMMENT ''绑定的小程序用户ID'' AFTER `del_flag`',
|
'SELECT 1'
|
);
|
PREPARE column_stmt FROM @column_sql;
|
EXECUTE column_stmt;
|
DEALLOCATE PREPARE column_stmt;
|
|
SET @index_exists := (
|
SELECT COUNT(1)
|
FROM information_schema.STATISTICS
|
WHERE TABLE_SCHEMA = DATABASE()
|
AND TABLE_NAME = 't_vin_management'
|
AND INDEX_NAME = 'idx_app_user_id'
|
);
|
SET @index_sql := IF(
|
@index_exists = 0,
|
'ALTER TABLE `t_vin_management` ADD INDEX `idx_app_user_id` (`app_user_id`)',
|
'SELECT 1'
|
);
|
PREPARE index_stmt FROM @index_sql;
|
EXECUTE index_stmt;
|
DEALLOCATE PREPARE index_stmt;
|