mirror of https://github.com/calzoneman/sync.git
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:
parent
4102d6eaf2
commit
70b875c0e9
|
@ -41,19 +41,9 @@ module.exports.checkVersion = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
function update(version, cb) {
|
function update(version, cb) {
|
||||||
if (version < 3 && hasUpdates.indexOf(2) < 0) {
|
if (version < 4) {
|
||||||
addMetaColumnToLibraries(cb);
|
LOGGER.error('Cannot auto-upgrade: db_version 4 is too old!');
|
||||||
} else if (version < 4) {
|
process.exit(1);
|
||||||
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();
|
|
||||||
})
|
|
||||||
} else if (version < 5) {
|
} else if (version < 5) {
|
||||||
fixUtf8mb4(cb);
|
fixUtf8mb4(cb);
|
||||||
} else if (version < 6) {
|
} 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) {
|
function fixUtf8mb4(cb) {
|
||||||
var queries = [
|
var queries = [
|
||||||
"ALTER TABLE `users` MODIFY `profile` TEXT CHARACTER SET utf8mb4 NOT NULL",
|
"ALTER TABLE `users` MODIFY `profile` TEXT CHARACTER SET utf8mb4 NOT NULL",
|
||||||
|
|
13
src/main.js
13
src/main.js
|
@ -28,19 +28,6 @@ function handleLine(line) {
|
||||||
if (line === '/reload') {
|
if (line === '/reload') {
|
||||||
LOGGER.info('Reloading config');
|
LOGGER.info('Reloading config');
|
||||||
Config.load('config.yaml');
|
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) {
|
} else if (line.indexOf('/switch') === 0) {
|
||||||
const args = line.split(' ');
|
const args = line.split(' ');
|
||||||
args.shift();
|
args.shift();
|
||||||
|
|
Loading…
Reference in New Issue