98 lines
2.2 KiB
JavaScript
98 lines
2.2 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
|
|
module.exports = (sequelize) => {
|
|
const Device = sequelize.define('Device', {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
primaryKey: true,
|
|
autoIncrement: true,
|
|
allowNull: false,
|
|
comment: 'Unique device identifier'
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
comment: 'Human-readable device name'
|
|
},
|
|
geo_lat: {
|
|
type: DataTypes.DECIMAL(10, 8),
|
|
allowNull: true,
|
|
comment: 'Device latitude coordinate'
|
|
},
|
|
geo_lon: {
|
|
type: DataTypes.DECIMAL(11, 8),
|
|
allowNull: true,
|
|
comment: 'Device longitude coordinate'
|
|
},
|
|
location_description: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true,
|
|
comment: 'Human-readable location description'
|
|
},
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: true,
|
|
comment: 'Whether the device is currently active'
|
|
},
|
|
is_approved: {
|
|
type: DataTypes.BOOLEAN,
|
|
defaultValue: false,
|
|
comment: 'Whether the device is approved to send data'
|
|
},
|
|
last_heartbeat: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
comment: 'Timestamp of last heartbeat received'
|
|
},
|
|
heartbeat_interval: {
|
|
type: DataTypes.INTEGER,
|
|
defaultValue: 300, // 5 minutes
|
|
comment: 'Expected heartbeat interval in seconds'
|
|
},
|
|
firmware_version: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
comment: 'Device firmware version'
|
|
},
|
|
installation_date: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true,
|
|
comment: 'When the device was installed'
|
|
},
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true,
|
|
comment: 'Additional notes about the device'
|
|
},
|
|
created_at: {
|
|
type: DataTypes.DATE,
|
|
defaultValue: DataTypes.NOW
|
|
},
|
|
updated_at: {
|
|
type: DataTypes.DATE,
|
|
defaultValue: DataTypes.NOW
|
|
}
|
|
}, {
|
|
tableName: 'devices',
|
|
timestamps: true,
|
|
createdAt: 'created_at',
|
|
updatedAt: 'updated_at',
|
|
indexes: [
|
|
{
|
|
fields: ['geo_lat', 'geo_lon']
|
|
},
|
|
{
|
|
fields: ['last_heartbeat']
|
|
},
|
|
{
|
|
fields: ['is_active']
|
|
},
|
|
{
|
|
fields: ['is_approved']
|
|
}
|
|
]
|
|
});
|
|
|
|
return Device;
|
|
};
|