mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
a script that allows importing old etherpad db
this script allows you to import the sql file generated with convert.js into all supported dbms, not only MySQL
This commit is contained in:
parent
0c9214bb27
commit
6dfc5f2c88
1 changed files with 45 additions and 0 deletions
45
bin/importSqlFile.js
Normal file
45
bin/importSqlFile.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
var startTime = new Date().getTime();
|
||||||
|
var fs = require("fs");
|
||||||
|
var db = require("../src/node/db/DB");
|
||||||
|
//var async = require("../src/node_modules/async");
|
||||||
|
|
||||||
|
var sqlFile = process.argv[2];
|
||||||
|
|
||||||
|
//stop if the settings file is not set
|
||||||
|
if(!sqlFile)
|
||||||
|
{
|
||||||
|
console.error("Use: node importSqlIntoRedis.js $SQLFILE");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
log("initializing db");
|
||||||
|
db.init(function(){
|
||||||
|
log("done");
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function log(str)
|
||||||
|
{
|
||||||
|
console.log((new Date().getTime() - startTime)/1000 + "\t" + str);
|
||||||
|
}
|
Loading…
Reference in a new issue