2013-03-06 17:16:30 +00:00
|
|
|
var startTime = new Date().getTime();
|
|
|
|
|
2013-03-06 21:08:14 +00:00
|
|
|
require("ep_etherpad-lite/node_modules/npm").load({}, function(er,npm) {
|
2013-03-06 17:16:30 +00:00
|
|
|
|
2013-03-06 21:08:14 +00:00
|
|
|
var fs = require("fs");
|
|
|
|
var db = require("ep_etherpad-lite/node/db/DB");;
|
|
|
|
|
|
|
|
var sqlFile = process.argv[2];
|
|
|
|
|
|
|
|
//stop if the settings file is not set
|
|
|
|
if(!sqlFile)
|
|
|
|
{
|
|
|
|
console.error("Use: node importSqlFile.js $SQLFILE");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
log("initializing db");
|
|
|
|
db.init(function(){
|
|
|
|
log("done");
|
2013-03-06 17:16:30 +00:00
|
|
|
|
2013-03-06 21:08:14 +00:00
|
|
|
log("open output file...");
|
2013-03-06 21:28:00 +00:00
|
|
|
var lines = fs.readFileSync(sqlFile, 'utf8').split("\n");;
|
2013-03-06 21:08:14 +00:00
|
|
|
|
2013-03-06 21:28:00 +00:00
|
|
|
var count = lines.length;
|
2013-03-06 21:08:14 +00:00
|
|
|
var keyNo = 0;
|
|
|
|
|
2013-03-06 21:36:00 +00:00
|
|
|
process.stdout.write("Start importing " + count + " keys...\n");
|
2013-03-06 21:28:00 +00:00
|
|
|
lines.forEach(function(l) {
|
2013-03-06 21:08:14 +00:00
|
|
|
if (l.substr(0, 27) == "REPLACE INTO store VALUES (") {
|
|
|
|
var pos = l.indexOf("', '");
|
|
|
|
var key = l.substr(28, pos - 28);
|
|
|
|
var value = l.substr(pos + 4);
|
|
|
|
value = value.substr(0, value.length - 3);
|
|
|
|
db.db.set(key, value, null);
|
|
|
|
keyNo++;
|
2013-03-06 21:36:00 +00:00
|
|
|
if (keyNo % 1000 == 0) {
|
|
|
|
process.stdout.write(" " + keyNo + "/" + count);
|
2013-03-06 21:28:00 +00:00
|
|
|
}
|
2013-03-06 21:08:14 +00:00
|
|
|
}
|
|
|
|
});
|
2013-03-06 21:28:00 +00:00
|
|
|
process.stdout.write("\n");
|
2013-03-06 21:08:14 +00:00
|
|
|
|
|
|
|
db.db.doShutdown(function() {
|
|
|
|
log("finished, imported " + keyNo + " keys.");
|
|
|
|
process.exit(0);
|
|
|
|
});
|
2013-03-06 17:16:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function log(str)
|
|
|
|
{
|
|
|
|
console.log((new Date().getTime() - startTime)/1000 + "\t" + str);
|
|
|
|
}
|