2014-02-01 18:41:06 +00:00
|
|
|
var db = require("../database");
|
|
|
|
var Logger = require("../logger");
|
2014-01-28 00:23:31 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|