2021-01-02 16:33:01 +00:00
|
|
|
require('npm').load({}, (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`
|
|
|
|
|
|
|
|
|
2021-01-02 16:33:01 +00:00
|
|
|
const settings = require('../src/node/utils/Settings');
|
|
|
|
let dirty = require('dirty');
|
|
|
|
const ueberDB = require('ueberdb2');
|
|
|
|
const log4js = require('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
|
|
|
};
|
2020-11-23 18:21:51 +00:00
|
|
|
const db = new ueberDB.database(settings.dbType, settings.dbSettings, dbWrapperSettings, log4js.getLogger('ueberDB'));
|
|
|
|
let i = 0;
|
|
|
|
let length = 0;
|
|
|
|
|
|
|
|
db.init(() => {
|
|
|
|
console.log('Waiting for dirtyDB to parse its file.');
|
|
|
|
dirty = dirty('var/dirty.db').on('load', () => {
|
|
|
|
dirty.forEach(() => {
|
2020-05-08 20:17:31 +00:00
|
|
|
length++;
|
|
|
|
});
|
|
|
|
console.log(`Found ${length} records, processing now.`);
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
dirty.forEach(async (key, value) => {
|
|
|
|
const error = await db.set(key, value);
|
2020-05-08 20:17:31 +00:00
|
|
|
console.log(`Wrote record ${i}`);
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i === length) {
|
2020-11-23 18:21:51 +00:00
|
|
|
console.log('finished, just clearing up for a bit...');
|
|
|
|
setTimeout(() => {
|
2020-05-08 20:17:31 +00:00
|
|
|
process.exit(0);
|
|
|
|
}, 5000);
|
|
|
|
}
|
2020-05-08 20:17:31 +00:00
|
|
|
});
|
2020-11-23 18:21:51 +00:00
|
|
|
console.log('Please wait for all records to flush to database, then kill this process.');
|
2015-11-22 07:15:46 +00:00
|
|
|
});
|
2020-11-23 18:21:51 +00:00
|
|
|
console.log('done?');
|
2015-11-22 07:15:46 +00:00
|
|
|
});
|
|
|
|
});
|