spark-server/migrations/0019_devices.sql
2026-09-23 17:11:56 +08:00

29 lines
1.5 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.

-- Physical t_devices registry + slim t_user_devices + login log app_id.
CREATE TABLE IF NOT EXISTS t_devices (
device_id BIGINT UNSIGNED NOT NULL COMMENT 'JWT did;多 App 同机共用',
fingerprint_hash CHAR(64) NOT NULL COMMENT '物理指纹 SHA256 hex,不含 app_id',
device_type TINYINT UNSIGNED NOT NULL COMMENT 'device_type 枚举 1=ios 2=android …',
device_name VARCHAR(64) NOT NULL DEFAULT '' COMMENT '最近 login 上报设备名',
idfv VARCHAR(36) NOT NULL DEFAULT '' COMMENT 'iOS IDFV',
android_id VARCHAR(20) NOT NULL DEFAULT '' COMMENT 'Android ID',
last_client_ip VARCHAR(30) NOT NULL DEFAULT '' COMMENT '最近 RealIP',
created_at DATETIME(3) NOT NULL COMMENT '首次注册',
updated_at DATETIME(3) NOT NULL COMMENT '最近 touch',
PRIMARY KEY (device_id),
UNIQUE KEY uk_fingerprint (fingerprint_hash)
) COMMENT='物理设备;与用户、App 无关';
ALTER TABLE t_user_login_logs
ADD COLUMN app_id TINYINT UNSIGNED NOT NULL DEFAULT 0
COMMENT '当次登录 app_id' AFTER device_id;
ALTER TABLE t_user_devices
ADD COLUMN last_active_at DATETIME(3) NULL COMMENT '该用户在此设备最近活跃' AFTER last_login_at;
ALTER TABLE t_user_devices DROP COLUMN platform;
ALTER TABLE t_user_devices DROP COLUMN device_name;
ALTER TABLE t_user_devices DROP COLUMN app_version;
ALTER TABLE t_user_devices DROP COLUMN language;
ALTER TABLE t_user_devices DROP COLUMN last_ip;