Add console command for deleting old channel tables
This commit is contained in:
parent
c768d9595c
commit
36c4e41131
2 changed files with 44 additions and 3 deletions
|
|
@ -26,8 +26,7 @@ module.exports.checkVersion = function () {
|
|||
var next = function () {
|
||||
hasUpdates.push(v);
|
||||
if (v < DB_VERSION) {
|
||||
update(v++, next);
|
||||
} else {
|
||||
update(v++, next); } else {
|
||||
db.query("UPDATE `meta` SET `value`=? WHERE `key`='db_version'",
|
||||
[DB_VERSION]);
|
||||
}
|
||||
|
|
@ -45,7 +44,11 @@ function update(version, cb) {
|
|||
Q.fcall(mergeChannelLibraries),
|
||||
Q.fcall(mergeChannelRanks),
|
||||
Q.fcall(mergeChannelBans)
|
||||
]).done(cb)
|
||||
]).done(function () {
|
||||
Logger.syslog.log("Merged channel tables. Please verify that everything " +
|
||||
"is working correctly, and then type '/delete_old_tables'" +
|
||||
" into the CyTube process to remove the unused tables.");
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,3 +185,35 @@ function mergeChannelBans(cb) {
|
|||
}
|
||||
}).done(cb);
|
||||
}
|
||||
|
||||
module.exports.deleteOldChannelTables = function (cb) {
|
||||
Q.nfcall(db.query, "SHOW TABLES")
|
||||
.then(function (rows) {
|
||||
rows = rows.map(function (r) {
|
||||
return r[Object.keys(r)[0]];
|
||||
}).filter(function (r) {
|
||||
return r.match(/chan_(.*?)_(library|ranks|bans)$/);
|
||||
});
|
||||
|
||||
var queue = [];
|
||||
rows.forEach(function (table) {
|
||||
queue.push(Q.nfcall(db.query, "DROP TABLE `" + table + "`")
|
||||
.then(function () {
|
||||
Logger.syslog.log("Deleted " + table);
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Deleting " + table + " failed: " + err);
|
||||
if (err.stack) {
|
||||
Logger.errlog.log(err.stack);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
return Q.all(queue);
|
||||
}).catch(function (err) {
|
||||
Logger.errlog.log("Deleting old tables failed: " + err);
|
||||
if (err.stack) {
|
||||
Logger.errlog.log(err.stack);
|
||||
}
|
||||
}).done(cb);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue