fix(server): devices 唯一键改 (user_id,uuid) —— 同机换账号不再 403 死结(F3,#27)
device_id 按安装持久、跨账号复用;旧全局 UNIQUE(uuid) 使同机第二账号注册永远 403 → ConnectNode 判 DEVICE_NOT_REGISTERED,提示的「重新登录」无法自救。 - migration 21(sqlite/mysql):UNIQUE(uuid)→UNIQUE(user_id,uuid);platform 放行 linux(normalizePlatform 早已接受,旧 CHECK/ENUM 会拒)。SQLite 表重建用 rename→重建→复制→drop 次序,单事务内不触发 sessions 的级联清空(FK ON)。 - 查找全部收口为按 (user,uuid) 作用域(重复 uuid 跨用户后全局查询歧义): findDeviceByUserUUIDTx / FindByUserUUID;Register 删跨用户 Forbidden 分支; Delete/ForceLogout/Rename 对他人设备返回 404(不可见);SessionActive 删 「非本人 fail-safe」分支,dev==nil→false 语义不变。 - 测试:SQLite 真迁移库 F3 回归(两账号同 uuid 各自成行/同用户重复拒/linux 入库/ sessions 重建后级联仍成立)+ MySQL 集成测试 schema 同步与双账号用例。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
-- 回退:UNIQUE(user_id,uuid) → 全局 UNIQUE(uuid),platform ENUM 去掉 linux。
|
||||
-- 有损:同一 uuid 跨用户的重复行只保留最早一行(id 最小),linux 平台行删除。
|
||||
|
||||
DELETE d1 FROM devices d1
|
||||
JOIN devices d2 ON d1.uuid = d2.uuid AND d1.id > d2.id;
|
||||
|
||||
DELETE FROM devices WHERE platform = 'linux';
|
||||
|
||||
ALTER TABLE devices
|
||||
DROP INDEX uniq_devices_user_uuid,
|
||||
ADD UNIQUE KEY uuid (uuid),
|
||||
MODIFY platform ENUM('ios','android','windows','macos') NOT NULL;
|
||||
@@ -0,0 +1,11 @@
|
||||
-- 设备唯一键 UNIQUE(uuid) → UNIQUE(user_id, uuid)(F3:同机换账号 403 死结)
|
||||
--
|
||||
-- device_id 是客户端按「安装」生成并持久的,跨账号复用;全局 UNIQUE(uuid) 使同一台
|
||||
-- 机器登第二个账号时 RegisterIfAbsent 永远 403。改为按用户隔离:同一物理设备在每个
|
||||
-- 账号下各有一行。顺手给 platform ENUM 加 linux(normalizePlatform 已接受,列会拒)。
|
||||
-- MySQL 可原地 ALTER,无需重建(列级 UNIQUE 的隐式索引名 = 列名 uuid)。
|
||||
|
||||
ALTER TABLE devices
|
||||
DROP INDEX uuid,
|
||||
ADD UNIQUE KEY uniq_devices_user_uuid (user_id, uuid),
|
||||
MODIFY platform ENUM('ios','android','windows','macos','linux') NOT NULL;
|
||||
Reference in New Issue
Block a user