2013-03-06 18:16:30 +01:00
|
|
|
var startTime = new Date().getTime();
|
|
|
|
|
2013-03-06 22:08:14 +01:00
|
|
|
require("ep_etherpad-lite/node_modules/npm").load({}, function(er,npm) {
|
2013-03-06 18:16:30 +01:00
|
|
|
|
2013-03-06 22:08:14 +01: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 18:16:30 +01:00
|
|
|
|
2013-03-06 22:08:14 +01:00
|
|
|
log("open output file...");
|
|
|
|
var file = fs.readFileSync(sqlFile, 'utf8');
|
|
|
|
|
|
|
|
var keyNo = 0;
|
|
|
|
|
|
|
|
file.split("\n").forEach(function(l) {
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
db.db.doShutdown(function() {
|
|
|
|
log("finished, imported " + keyNo + " keys.");
|
|
|
|
process.exit(0);
|
|
|
|
});
|
2013-03-06 18:16:30 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function log(str)
|
|
|
|
{
|
|
|
|
console.log((new Date().getTime() - startTime)/1000 + "\t" + str);
|
|
|
|
}
|