diff --git a/server/db/patches/004_fix_up_column_name_for_monitoring.sql b/server/db/patches/004_fix_up_column_name_for_monitoring.sql new file mode 100644 index 0000000..ef36218 --- /dev/null +++ b/server/db/patches/004_fix_up_column_name_for_monitoring.sql @@ -0,0 +1,45 @@ +-- sqlite only supports a limited subset of ALTER TABLE, thus this workaround + +ALTER TABLE node_state RENAME TO tmp_node_state; + +CREATE TABLE node_state ( + id INTEGER PRIMARY KEY, + + mac VARCHAR(17) NOT NULL UNIQUE, + + state VARCHAR(10) NOT NULL, + last_seen DATETIME NOT NULL, + + import_timestamp DATETIME NOT NULL, + + last_status_mail_sent DATETIME, + last_status_mail_type VARCHAR(20), + + created_at DATETIME DEFAULT (strftime('%s','now')) NOT NULL, + modified_at DATETIME DEFAULT (strftime('%s','now')) NOT NULL +); + +INSERT INTO node_state( + id, + mac, + state, + last_seen, + import_timestamp, + last_status_mail_sent, + last_status_mail_type, + created_at, + modified_at +) +SELECT + id, + mac, + state, + last_seen, + import_timestamp, + last_status_mail_send, + last_status_mail_type, + created_at, + modified_at +FROM tmp_node_state; + +DROP TABLE tmp_node_state; diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index cfdd5e0..d2be71c 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -34,7 +34,7 @@ angular.module('ffffng') return Database.run( 'INSERT INTO node_state ' + - '(mac, state, last_seen, import_timestamp, last_status_mail_send, last_status_mail_type) ' + + '(mac, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' + 'VALUES (?, ?, ?, ?, ?, ?)', [ node.mac, @@ -267,7 +267,7 @@ angular.module('ffffng') var now = moment().unix(); Database.run( 'UPDATE node_state ' + - 'SET modified_at = ?, last_status_mail_send = ?, last_status_mail_type = ?' + + 'SET modified_at = ?, last_status_mail_sent = ?, last_status_mail_type = ?' + 'WHERE id = ?', [ now, now, mailType, @@ -330,19 +330,19 @@ angular.module('ffffng') var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : ''; var schedule = MONITORING_OFFLINE_MAILS_SCHEDULE[mailNumber]; - var scheduleTimeBefore = moment().subtract(schedule.amount, schedule.unit); + var scheduledTimeBefore = moment().subtract(schedule.amount, schedule.unit); Database.all( 'SELECT * FROM node_state ' + 'WHERE modified_at < ? AND state = ? AND (last_status_mail_type = ?' + allowNull + ') AND ' + - 'last_seen <= ? AND last_status_mail_send <= ? ' + + 'last_seen <= ? AND last_status_mail_sent <= ? ' + 'ORDER BY id ASC LIMIT ?', [ startTime.unix(), 'OFFLINE', previousType, - scheduleTimeBefore.unix(), - scheduleTimeBefore.unix(), + scheduledTimeBefore.unix(), + scheduledTimeBefore.unix(), MONITORING_MAILS_DB_BATCH_SIZE ],