2013-05-31 04:48:11 +00:00
|
|
|
var Config = require("./config.js");
|
|
|
|
var Database = require("./database.js");
|
|
|
|
|
2013-06-27 20:41:59 +00:00
|
|
|
//Config.DEBUG = true;
|
2013-05-31 04:48:11 +00:00
|
|
|
Database.setup(Config);
|
|
|
|
Database.init();
|
|
|
|
var query;
|
|
|
|
var db = Database.getConnection();
|
|
|
|
|
|
|
|
// Check for already existing
|
2013-06-27 20:41:59 +00:00
|
|
|
query = "SELECT owner FROM channels WHERE 1";
|
2013-05-31 04:48:11 +00:00
|
|
|
if(!db.querySync(query)) {
|
2013-06-27 20:41:59 +00:00
|
|
|
query = "ALTER TABLE channels ADD owner VARCHAR(20) NOT NULL";
|
2013-05-31 04:48:11 +00:00
|
|
|
var res = db.querySync(query);
|
|
|
|
if(!res) {
|
|
|
|
console.log(db);
|
|
|
|
console.log("Update failed!");
|
|
|
|
}
|
2013-06-27 20:41:59 +00:00
|
|
|
else {
|
|
|
|
populateChannelOwners();
|
|
|
|
}
|
2013-05-31 04:48:11 +00:00
|
|
|
}
|
2013-07-09 16:28:54 +00:00
|
|
|
|
|
|
|
console.log("Fixing user playlist bug");
|
|
|
|
query = "ALTER TABLE user_playlists DROP PRIMARY KEY, ADD PRIMARY KEY (user, name)";
|
|
|
|
if(!db.querySync(query)) {
|
|
|
|
console.log("Something went wrong");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("fixed");
|
|
|
|
}
|
2013-05-31 04:48:11 +00:00
|
|
|
db.closeSync();
|
|
|
|
process.exit(0);
|
2013-06-27 20:41:59 +00:00
|
|
|
|
|
|
|
function populateChannelOwners() {
|
|
|
|
query = "SELECT * FROM channels WHERE 1";
|
|
|
|
var res = db.querySync(query);
|
|
|
|
if(!res) {
|
|
|
|
console.log(db);
|
|
|
|
console.log("Update failed!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var channels = res.fetchAllSync();
|
|
|
|
channels.forEach(function(chan) {
|
|
|
|
chan = chan.name;
|
|
|
|
query = "SELECT name FROM `chan_"+chan+"_ranks` WHERE rank>=10 ORDER BY rank";
|
|
|
|
res = db.querySync(query);
|
|
|
|
if(!res) {
|
|
|
|
console.log(db);
|
2013-07-03 20:04:50 +00:00
|
|
|
console.log("failed to fix "+chan);
|
2013-06-27 20:41:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var results = res.fetchAllSync();
|
|
|
|
if(results.length == 0) {
|
|
|
|
console.log("bad channel: " + chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var owner = results[0].name;
|
|
|
|
query = "UPDATE channels SET owner='"+owner+"' WHERE name='"+chan+"'";
|
|
|
|
console.log("setting owner=" + owner + " for /r/" + chan);
|
|
|
|
res = db.querySync(query);
|
|
|
|
if(!res) {
|
|
|
|
console.log(db);
|
|
|
|
console.log("Update failed!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|