将历史补单字段合并到初始化SQL
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
-- 历史补单与服务中状态(可重复执行)
|
||||
-- 不执行数据迁移,仅为新部署环境补充字段。
|
||||
SET @db_name = DATABASE();
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order MODIFY COLUMN user_id BIGINT UNSIGNED NULL COMMENT ''客户用户ID,补单可为空''',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'user_id' AND is_nullable = 'YES');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN customer_name_snapshot VARCHAR(100) NULL COMMENT ''补单客户名称快照'' AFTER customer_remark',
|
||||
'SELECT 1') FROM information_schema.columns WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'customer_name_snapshot');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN customer_phone_snapshot VARCHAR(32) NULL COMMENT ''补单客户手机号快照'' AFTER customer_name_snapshot',
|
||||
'SELECT 1') FROM information_schema.columns WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'customer_phone_snapshot');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD COLUMN order_source VARCHAR(32) NOT NULL DEFAULT ''NORMAL_APPOINTMENT'' COMMENT ''订单来源'' AFTER customer_remark',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = @db_name AND table_name = 't_order' AND column_name = 'order_source');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order_item ADD COLUMN service_date DATE NULL COMMENT ''业务服务日期,历史补单无具体时间时使用'' AFTER appointment_time',
|
||||
'SELECT 1') FROM information_schema.columns
|
||||
WHERE table_schema = @db_name AND table_name = 't_order_item' AND column_name = 'service_date');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order ADD INDEX idx_order_source_status_delete (order_source, status, is_delete)',
|
||||
'SELECT 1') FROM information_schema.statistics
|
||||
WHERE table_schema = @db_name AND table_name = 't_order' AND index_name = 'idx_order_source_status_delete');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sql = (SELECT IF(COUNT(*) = 0,
|
||||
'ALTER TABLE t_order_item ADD INDEX idx_order_item_artist_service_date (artist_id, service_date, is_delete)',
|
||||
'SELECT 1') FROM information_schema.statistics
|
||||
WHERE table_schema = @db_name AND table_name = 't_order_item' AND index_name = 'idx_order_item_artist_service_date');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
Reference in New Issue
Block a user