Remove some ancient db upgrade stuff

If anyone is still running a database from 2014 they want to upgrade,
sorry.
This commit is contained in:
Calvin Montgomery 2017-08-13 22:19:47 -07:00
parent 4102d6eaf2
commit 70b875c0e9
2 changed files with 3 additions and 192 deletions

View File

@ -41,19 +41,9 @@ module.exports.checkVersion = function () {
};
function update(version, cb) {
if (version < 3 && hasUpdates.indexOf(2) < 0) {
addMetaColumnToLibraries(cb);
} else if (version < 4) {
Q.allSettled([
Q.nfcall(mergeChannelLibraries),
Q.nfcall(mergeChannelRanks),
Q.nfcall(mergeChannelBans)
]).done(function () {
LOGGER.info("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.");
cb();
})
if (version < 4) {
LOGGER.error('Cannot auto-upgrade: db_version 4 is too old!');
process.exit(1);
} else if (version < 5) {
fixUtf8mb4(cb);
} else if (version < 6) {
@ -71,172 +61,6 @@ function update(version, cb) {
}
}
function addMetaColumnToLibraries(cb) {
LOGGER.info("db version indicates channel libraries don't have " +
"meta column. Updating...");
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(/_library$/);
});
var queue = [];
rows.forEach(function (table) {
queue.push(Q.nfcall(db.query, "ALTER TABLE `" + table + "` ADD meta TEXT")
.then(function () {
LOGGER.info("Added meta column to " + table);
})
);
});
return Q.all(queue);
}).catch(function (err) {
LOGGER.error("Adding meta column to library tables failed: " + err);
}).done(cb);
}
function mergeChannelLibraries(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$/);
});
var queue = [];
rows.forEach(function (table) {
var name = table.match(/chan_(.*?)_library$/)[1];
queue.push(Q.nfcall(db.query,
"INSERT INTO `channel_libraries` SELECT id, title, seconds, type, meta, ?" +
" AS channel FROM `" + table + "`", [name])
.then(function () {
LOGGER.info("Copied " + table + " to channel_libraries");
}).catch(function (err) {
LOGGER.error("Copying " + table + " to channel_libraries failed: " +
err);
if (err.stack) {
LOGGER.error(err.stack);
}
})
);
});
return Q.all(queue);
}).catch(function (err) {
LOGGER.error("Copying libraries to channel_libraries failed: " + err);
if (err.stack) {
LOGGER.error(err.stack);
}
}).done(function () { cb(null); });
}
function mergeChannelRanks(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_(.*?)_ranks$/);
});
var queue = [];
rows.forEach(function (table) {
var name = table.match(/chan_(.*?)_ranks$/)[1];
queue.push(Q.nfcall(db.query,
"INSERT INTO `channel_ranks` SELECT name, rank, ?" +
" AS channel FROM `" + table + "`", [name])
.then(function () {
LOGGER.info("Copied " + table + " to channel_ranks");
}).catch(function (err) {
LOGGER.error("Copying " + table + " to channel_ranks failed: " +
err);
if (err.stack) {
LOGGER.error(err.stack);
}
})
);
});
return Q.all(queue);
}).catch(function (err) {
LOGGER.error("Copying ranks to channel_ranks failed: " + err);
if (err.stack) {
LOGGER.error(err.stack);
}
}).done(function () { cb(null); });
}
function mergeChannelBans(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_(.*?)_bans$/);
});
var queue = [];
rows.forEach(function (table) {
var name = table.match(/chan_(.*?)_bans$/)[1];
queue.push(Q.nfcall(db.query,
"INSERT INTO `channel_bans` SELECT id, ip, name, bannedby, reason, ?" +
" AS channel FROM `" + table + "`", [name])
.then(function () {
LOGGER.info("Copied " + table + " to channel_bans");
}).catch(function (err) {
LOGGER.error("Copying " + table + " to channel_bans failed: " +
err);
if (err.stack) {
LOGGER.error(err.stack);
}
})
);
});
return Q.all(queue);
}).catch(function (err) {
LOGGER.error("Copying ranks to channel_bans failed: " + err);
if (err.stack) {
LOGGER.error(err.stack);
}
}).done(function () { cb(null); });
}
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.info("Deleted " + table);
}).catch(function (err) {
LOGGER.error("Deleting " + table + " failed: " + err);
if (err.stack) {
LOGGER.error(err.stack);
}
})
);
});
return Q.all(queue);
}).catch(function (err) {
LOGGER.error("Deleting old tables failed: " + err);
if (err.stack) {
LOGGER.error(err.stack);
}
}).done(cb);
};
function fixUtf8mb4(cb) {
var queries = [
"ALTER TABLE `users` MODIFY `profile` TEXT CHARACTER SET utf8mb4 NOT NULL",

View File

@ -28,19 +28,6 @@ function handleLine(line) {
if (line === '/reload') {
LOGGER.info('Reloading config');
Config.load('config.yaml');
} else if (line === '/gc') {
if (global && global.gc) {
LOGGER.info('Running GC');
global.gc();
} else {
LOGGER.info('Failed to invoke GC: node started without --expose-gc');
}
} else if (line === '/delete_old_tables') {
require('./database/update').deleteOldChannelTables(function (err) {
if (!err) {
LOGGER.info('Deleted old channel tables');
}
});
} else if (line.indexOf('/switch') === 0) {
const args = line.split(' ');
args.shift();