更新ASIN库新需求
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
SET @uploader_user_id_col_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_dedupe_total_data'
|
||||
AND COLUMN_NAME = 'uploader_user_id'
|
||||
);
|
||||
|
||||
SET @sql_add_uploader_user_id := IF(
|
||||
@uploader_user_id_col_exists = 0,
|
||||
'ALTER TABLE biz_dedupe_total_data ADD COLUMN uploader_user_id BIGINT NULL COMMENT ''上传用户ID'' AFTER data_value',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt_add_uploader_user_id FROM @sql_add_uploader_user_id;
|
||||
EXECUTE stmt_add_uploader_user_id;
|
||||
DEALLOCATE PREPARE stmt_add_uploader_user_id;
|
||||
|
||||
SET @uploader_username_col_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_dedupe_total_data'
|
||||
AND COLUMN_NAME = 'uploader_username'
|
||||
);
|
||||
|
||||
SET @sql_add_uploader_username := IF(
|
||||
@uploader_username_col_exists = 0,
|
||||
'ALTER TABLE biz_dedupe_total_data ADD COLUMN uploader_username VARCHAR(64) NULL COMMENT ''上传用户名'' AFTER uploader_user_id',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt_add_uploader_username FROM @sql_add_uploader_username;
|
||||
EXECUTE stmt_add_uploader_username;
|
||||
DEALLOCATE PREPARE stmt_add_uploader_username;
|
||||
|
||||
SET @dedupe_root_user_id := (
|
||||
SELECT id
|
||||
FROM users
|
||||
WHERE LOWER(COALESCE(role, '')) = 'super_admin'
|
||||
OR (COALESCE(role, '') = '' AND is_admin = 1 AND created_by_id IS NULL)
|
||||
ORDER BY CASE WHEN username = 'root' THEN 0 ELSE 1 END, id ASC
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
SET @dedupe_root_username := (
|
||||
SELECT username
|
||||
FROM users
|
||||
WHERE id = @dedupe_root_user_id
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS dedupe_root_user_guard;
|
||||
CREATE TEMPORARY TABLE dedupe_root_user_guard (
|
||||
user_id BIGINT NOT NULL,
|
||||
username VARCHAR(64) NOT NULL
|
||||
);
|
||||
INSERT INTO dedupe_root_user_guard (user_id, username)
|
||||
VALUES (@dedupe_root_user_id, @dedupe_root_username);
|
||||
DROP TEMPORARY TABLE dedupe_root_user_guard;
|
||||
|
||||
UPDATE biz_dedupe_total_data
|
||||
SET uploader_user_id = @dedupe_root_user_id,
|
||||
uploader_username = @dedupe_root_username
|
||||
WHERE uploader_user_id IS NULL
|
||||
OR uploader_username IS NULL
|
||||
OR uploader_username = '';
|
||||
|
||||
ALTER TABLE biz_dedupe_total_data
|
||||
MODIFY COLUMN uploader_user_id BIGINT NOT NULL COMMENT '上传用户ID',
|
||||
MODIFY COLUMN uploader_username VARCHAR(64) NOT NULL COMMENT '上传用户名';
|
||||
|
||||
SET @uploader_user_id_idx_exists := (
|
||||
SELECT COUNT(*)
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'biz_dedupe_total_data'
|
||||
AND INDEX_NAME = 'idx_uploader_user_id_id'
|
||||
);
|
||||
|
||||
SET @sql_add_uploader_user_id_idx := IF(
|
||||
@uploader_user_id_idx_exists = 0,
|
||||
'ALTER TABLE biz_dedupe_total_data ADD INDEX idx_uploader_user_id_id (uploader_user_id, id)',
|
||||
'SELECT 1'
|
||||
);
|
||||
PREPARE stmt_add_uploader_user_id_idx FROM @sql_add_uploader_user_id_idx;
|
||||
EXECUTE stmt_add_uploader_user_id_idx;
|
||||
DEALLOCATE PREPARE stmt_add_uploader_user_id_idx;
|
||||
Reference in New Issue
Block a user