pad.libre-service.eu-etherpad/bin/migrateDirtyDBtoRealDB.js
JannikStreek 04063d664b
cleanup after workspace refactoring (#6174)
* fix bin folder and workflows as far its possible

cleanup of dockerfile

changed paths of scripts

add lock file

fix working directory for workflows

fix windows bin

fix travis (is travis used anyway?)

fix package refs

remove pnpm-lock file in root as these conflicts with the docker volume setup

optimize comments

use install again

refactor prod image call to run

fix --workspace can only be used inside a workspace

correct comment

try fix pipeline

try fix pipeline for upgrade-from-latest-release

install all deps

smaller adjustments

save

update dockerfile

remove workspace command

fix run test command

start repair latest release workflow

start repair latest release workflow

start repair latest release workflow

further repairs

* remove test plugin from docker compose
2024-02-21 21:50:11 +01:00

56 lines
2 KiB
JavaScript

'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; });
(async () => {
// 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.
// It might be necessary to run the script using more memory:
// `node --max-old-space-size=4096 src/bin/migrateDirtyDBtoRealDB.js`
const dirtyDb = require('dirty');
const log4js = require('log4js');
const settings = require('./src/node/utils/Settings');
const ueberDB = require('ueberdb2');
const util = require('util');
const dbWrapperSettings = {
cache: '0', // The cache slows things down when you're mostly writing.
writeInterval: 0, // Write directly to the database, don't buffer
};
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(`${__dirname}/../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);
});
await Promise.all(p);
console.log(`Wrote all ${numWritten} records`);
await util.promisify(db.close.bind(db))();
console.log('Finished.');
})();