chore: 并入 iotlcm-app 历史到 app/(原提交 f40bda9)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:00 +08:00
1107 changed files with 147143 additions and 0 deletions
@@ -0,0 +1,62 @@
-- Fix terminal-card binding uniqueness.
-- Correct relation:
-- 1. One terminal user can bind multiple cards.
-- 2. One card can only be bound to one terminal user in the same tenant.
--
-- Before running the ALTER statements, check whether the same card is already
-- bound more than once. If this query returns rows, resolve those duplicates
-- first, otherwise the new unique index cannot be created.
SELECT `tenant_id`, `iccid`, COUNT(*) AS `duplicate_count`
FROM `t_sim_terminal`
GROUP BY `tenant_id`, `iccid`
HAVING COUNT(*) > 1;
SET @schema_name := DATABASE();
SET @sql := (
SELECT IF(
COUNT(*) > 0,
'ALTER TABLE `t_sim_terminal` DROP INDEX `uk_package_terminal`',
'SELECT 1'
)
FROM `information_schema`.`statistics`
WHERE `table_schema` = @schema_name
AND `table_name` = 't_sim_terminal'
AND `index_name` = 'uk_package_terminal'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql := (
SELECT IF(
COUNT(*) > 0,
'ALTER TABLE `t_sim_terminal` DROP INDEX `uk_sim_terminal_card`',
'SELECT 1'
)
FROM `information_schema`.`statistics`
WHERE `table_schema` = @schema_name
AND `table_name` = 't_sim_terminal'
AND `index_name` = 'uk_sim_terminal_card'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
ALTER TABLE `t_sim_terminal`
ADD UNIQUE KEY `uk_sim_terminal_card` (`tenant_id`, `iccid`);
SET @sql := (
SELECT IF(
COUNT(*) = 0,
'ALTER TABLE `t_sim_terminal` ADD KEY `idx_terminal_card` (`tenant_id`, `terminal_id`)',
'SELECT 1'
)
FROM `information_schema`.`statistics`
WHERE `table_schema` = @schema_name
AND `table_name` = 't_sim_terminal'
AND `index_name` = 'idx_terminal_card'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
File diff suppressed because one or more lines are too long