2021-01-18 08:53:15 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an
|
|
|
|
// unhandled rejection into an uncaught exception, which does cause Node.js to exit.
|
|
|
|
process.on('unhandledRejection', (err) => { throw err; });
|
|
|
|
|
|
|
|
const util = require('util');
|
|
|
|
|
|
|
|
require('ep_etherpad-lite/node_modules/npm').load({}, async (er, npm) => {
|
2020-11-23 18:21:51 +00:00
|
|
|
process.chdir(`${npm.root}/..`);
|
2015-11-22 07:15:46 +00:00
|
|
|
|
|
|
|
// This script requires that you have modified your settings.json file
|
|
|
|
// to work with a real database. Please make a backup of your dirty.db
|
|
|
|
// file before using this script, just to be safe.
|
|
|
|
|
2018-11-27 12:32:07 +00:00
|
|
|
// It might be necessary to run the script using more memory:
|
|
|
|
// `node --max-old-space-size=4096 bin/migrateDirtyDBtoRealDB.js`
|
|
|
|
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
const settings = require('ep_etherpad-lite/node/utils/Settings');
|
2021-01-18 08:53:15 +00:00
|
|
|
const dirtyDb = require('ep_etherpad-lite/node_modules/dirty');
|
|
|
|
const ueberDB = require('ep_etherpad-lite/node_modules/ueberdb2');
|
|
|
|
const log4js = require('ep_etherpad-lite/node_modules/log4js');
|
2020-11-23 18:21:51 +00:00
|
|
|
const dbWrapperSettings = {
|
|
|
|
cache: '0', // The cache slows things down when you're mostly writing.
|
|
|
|
writeInterval: 0, // Write directly to the database, don't buffer
|
2015-11-22 07:15:46 +00:00
|
|
|
};
|
2021-01-18 08:53:15 +00:00
|
|
|
const db = new ueberDB.database( // eslint-disable-line new-cap
|
|
|
|
settings.dbType,
|
|
|
|
settings.dbSettings,
|
|
|
|
dbWrapperSettings,
|
|
|
|
log4js.getLogger('ueberDB'));
|
|
|
|
await db.init();
|
|
|
|
|
|
|
|
console.log('Waiting for dirtyDB to parse its file.');
|
|
|
|
const dirty = dirtyDb('var/dirty.db');
|
|
|
|
const length = await new Promise((resolve) => { dirty.once('load', resolve); });
|
|
|
|
|
|
|
|
console.log(`Found ${length} records, processing now.`);
|
|
|
|
const p = [];
|
|
|
|
let numWritten = 0;
|
|
|
|
dirty.forEach((key, value) => {
|
|
|
|
let bcb, wcb;
|
|
|
|
p.push(new Promise((resolve, reject) => {
|
|
|
|
bcb = (err) => { if (err != null) return reject(err); };
|
|
|
|
wcb = (err) => {
|
|
|
|
if (err != null) return reject(err);
|
|
|
|
if (++numWritten % 100 === 0) console.log(`Wrote record ${numWritten} of ${length}`);
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
db.set(key, value, bcb, wcb);
|
2015-11-22 07:15:46 +00:00
|
|
|
});
|
2021-01-18 08:53:15 +00:00
|
|
|
await Promise.all(p);
|
|
|
|
console.log(`Wrote all ${numWritten} records`);
|
|
|
|
|
|
|
|
await util.promisify(db.close.bind(db))();
|
|
|
|
console.log('Finished.');
|
2015-11-22 07:15:46 +00:00
|
|
|
});
|