meteor_detection_system/meteor-web-backend/migrations/1754714100000_create-camera-management-tables.js

106 lines
2.8 KiB
JavaScript
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.

/**
* 相机设备管理相关表
*/
export const up = (pgm) => {
// 1. 相机设备表 (扩展现有设备表的概念,专门用于相机设备)
pgm.createTable('camera_devices', {
id: { type: 'serial', primaryKey: true },
device_id: {
type: 'varchar(255)',
unique: true,
notNull: true,
comment: '设备唯一标识符如CAM-001'
},
name: {
type: 'varchar(255)',
notNull: true,
comment: '相机设备名称'
},
location: {
type: 'varchar(255)',
notNull: true,
comment: '相机所在地点'
},
status: {
type: 'varchar(50)',
notNull: true,
default: 'offline',
comment: 'active, maintenance, offline'
},
last_seen_at: {
type: 'timestamptz',
comment: '最后活跃时间'
},
temperature: {
type: 'decimal(5,2)',
comment: '当前温度'
},
cooler_power: {
type: 'decimal(5,2)',
comment: '制冷功率百分比'
},
gain: {
type: 'integer',
comment: 'CCD增益值'
},
exposure_count: {
type: 'integer',
default: 0,
comment: '总曝光次数'
},
uptime: {
type: 'decimal(10,2)',
comment: '运行时间(小时)'
},
firmware_version: {
type: 'varchar(50)',
comment: '固件版本'
},
serial_number: {
type: 'varchar(100)',
unique: true,
comment: '设备序列号'
},
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') },
updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') }
});
// 2. 相机历史记录表 (存储相机状态的历史数据)
pgm.createTable('camera_history_records', {
id: { type: 'serial', primaryKey: true },
camera_device_id: {
type: 'integer',
notNull: true,
references: 'camera_devices(id)',
onDelete: 'CASCADE'
},
recorded_at: {
type: 'timestamptz',
notNull: true,
default: pgm.func('current_timestamp')
},
status: {
type: 'varchar(50)',
notNull: true,
comment: 'active, maintenance, offline'
},
temperature: { type: 'decimal(5,2)' },
cooler_power: { type: 'decimal(5,2)' },
gain: { type: 'integer' },
exposure_count: { type: 'integer' },
uptime: { type: 'decimal(10,2)' },
created_at: { type: 'timestamptz', notNull: true, default: pgm.func('current_timestamp') }
});
// 添加索引
pgm.createIndex('camera_devices', 'device_id');
pgm.createIndex('camera_devices', 'status');
pgm.createIndex('camera_history_records', 'camera_device_id');
pgm.createIndex('camera_history_records', 'recorded_at');
};
export const down = (pgm) => {
pgm.dropTable('camera_history_records');
pgm.dropTable('camera_devices');
};