gcx/backend/migrations/050_add_device_fields_to_te...

15 lines
823 B
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.

-- 为 telemetry_events 添加设备字段顶层列
-- 设备字段提升为独立列(而非放进 JSONB properties的原因
-- 按设备品牌/版本分组查询可以命中 B-tree 索引,千万级数据下毫秒级响应
-- 若放进 JSONB: properties->>'device_brand' 需全表扫描
ALTER TABLE telemetry_events
ADD COLUMN IF NOT EXISTS device_brand VARCHAR(64) NULL,
ADD COLUMN IF NOT EXISTS device_model VARCHAR(64) NULL,
ADD COLUMN IF NOT EXISTS device_os VARCHAR(32) NULL,
ADD COLUMN IF NOT EXISTS app_version VARCHAR(32) NULL,
ADD COLUMN IF NOT EXISTS locale VARCHAR(16) NULL;
CREATE INDEX IF NOT EXISTS idx_telemetry_events_device_brand ON telemetry_events(device_brand);
CREATE INDEX IF NOT EXISTS idx_telemetry_events_app_version ON telemetry_events(app_version);