fastbee/sql/iot_project_device_migration.sql
2026-08-02 07:52:40 +08:00

22 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ========================================
-- FastBee项目设备关联改造迁移脚本
-- 创建日期: 2026-08-01
-- 描述: 将项目-设备关联从两层关联表改为设备表直接外键
-- ========================================
-- 1. 设备表新增所属项目字段
ALTER TABLE `iot_device`
ADD COLUMN `project_id` BIGINT(20) DEFAULT NULL COMMENT '所属项目ID' AFTER `tenant_name`,
ADD INDEX `idx_project_id` (`project_id`);
-- 2. 废弃项目-分组关系表(未上线,无需迁移数据)
DROP TABLE IF EXISTS `iot_project_group`;
-- ========================================
-- 变更说明:
-- 1. 项目与设备的关系从"项目→分组→设备"两层间接关联,简化为"项目→设备"直接关联
-- 2. 一个设备最多属于一个项目(1:1),一个项目可包含多个设备(1:N)
-- 3. iot_device.project_id 为 NULL 表示设备未关联项目
-- 4. iot_group / iot_device_group 表保留,继续用于独立的设备分组管理功能
-- ========================================