feat(db): add M7 device management tables (device, sn_binding, swap_request)

This commit is contained in:
2026-05-25 00:54:42 +08:00
parent 0a43f8fbbe
commit b13d17702e
@@ -0,0 +1,49 @@
-- V7__device_management.sql
-- M7:设备主表
CREATE TABLE platform_device (
id BIGSERIAL PRIMARY KEY,
mid VARCHAR(128) NOT NULL UNIQUE,
alias VARCHAR(256),
site VARCHAR(256),
customer_id BIGINT REFERENCES platform_customer(id),
project_id BIGINT REFERENCES platform_project(id),
status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE',
first_seen_at TIMESTAMP WITH TIME ZONE,
last_heartbeat_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_platform_device_customer ON platform_device(customer_id);
CREATE INDEX idx_platform_device_project ON platform_device(project_id);
CREATE INDEX idx_platform_device_status ON platform_device(status);
-- M7:设备↔SN 绑定历史
CREATE TABLE platform_device_sn_binding (
id BIGSERIAL PRIMARY KEY,
device_id BIGINT NOT NULL REFERENCES platform_device(id),
license_sn_id BIGINT NOT NULL REFERENCES platform_license_sn(id),
bind_type VARCHAR(32) NOT NULL DEFAULT 'ACTIVATE',
bind_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
remark TEXT,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_binding_device ON platform_device_sn_binding(device_id);
CREATE INDEX idx_binding_sn ON platform_device_sn_binding(license_sn_id);
-- M7:换机申请
CREATE TABLE platform_device_swap_request (
id BIGSERIAL PRIMARY KEY,
old_device_id BIGINT NOT NULL REFERENCES platform_device(id),
new_mid VARCHAR(128) NOT NULL,
sn_id BIGINT NOT NULL REFERENCES platform_license_sn(id),
reason VARCHAR(512),
status VARCHAR(32) NOT NULL DEFAULT 'PENDING',
processed_by VARCHAR(256),
processed_at TIMESTAMP WITH TIME ZONE,
remark TEXT,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_swap_status ON platform_device_swap_request(status);