Persist announcements in the database
This commit is contained in:
parent
6498f6431b
commit
2c6edb38b8
4 changed files with 63 additions and 39 deletions
36
lib/database/update.js
Normal file
36
lib/database/update.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
var db = require("../database");
|
||||
var Logger = require("../logger");
|
||||
|
||||
const DB_VERSION = 1;
|
||||
|
||||
module.exports.checkVersion = function () {
|
||||
db.query("SELECT `key`,`value` FROM `meta` WHERE `key`=?", ["db_version"], function (err, rows) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rows.length === 0) {
|
||||
Logger.errlog.log("[Warning] db_version key missing from database. Setting " +
|
||||
"db_version=" + DB_VERSION);
|
||||
db.query("INSERT INTO `meta` (`key`, `value`) VALUES ('db_version', ?)",
|
||||
[DB_VERSION],
|
||||
function (err) {
|
||||
});
|
||||
} else {
|
||||
var v = parseInt(rows[0].value);
|
||||
var next = function () {
|
||||
if (v < DB_VERSION) {
|
||||
update(v++, next);
|
||||
} else {
|
||||
db.query("UPDATE `meta` SET `value`=? WHERE `key`='db_version'",
|
||||
[DB_VERSION]);
|
||||
}
|
||||
};
|
||||
update(v++, next);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function update(version, cb) {
|
||||
setImmediate(cb);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue