mirror of
https://github.com/ether/etherpad-lite.git
synced 2026-07-17 16:47:05 +00:00
Both scripts still called the pre-v6 callback-style ueberdb2 API, producing type errors (masked in places by `// @ts-ignore`) against the current promise-based signatures (`set(key, value)`, `init()`, `close()` — no callback/extra args): importSqlFile.ts(73) initDb(null) Expected 0 arguments, but got 1 migrateDirtyDBtoRealDB.ts(51) db.set(k,v,bcb,wcb) Expected 2 arguments, but got 4 migrateDirtyDBtoRealDB.ts(56) db.close(null) Expected 0 arguments, but got 1 migrateDirtyDBtoRealDB.ts(57) dirty.close(null) Expected 0 arguments, but got 1 - importSqlFile: drop the unused `util` import and the `util.promisify` wrappers; `await db.init()`, `await db.set(...)`, `await db.close()` directly. Removes two `// @ts-ignore` that were hiding the broken calls. - migrateDirtyDBtoRealDB: replace the bcb/wcb callback machinery with `await db.set(key, value)` in the loop and call `close()` with no args. Also fixes the progress log which referenced an undefined `length` instead of `keys.length`. Pure type/correctness cleanup; behaviour is unchanged (writes are now awaited, which is equivalent or safer). `tsc --noEmit` on the bin package is now clean. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
'use strict';
|
|
|
|
import process from 'node:process';
|
|
import {Database, DatabaseType} from "ueberdb2";
|
|
import log4js from 'log4js';
|
|
import settings from 'ep_etherpad-lite/node/utils/Settings';
|
|
|
|
// 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 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 Database( // eslint-disable-line new-cap
|
|
settings.dbType as DatabaseType,
|
|
settings.dbSettings,
|
|
dbWrapperSettings,
|
|
log4js.getLogger('ueberDB'));
|
|
await db.init();
|
|
|
|
console.log('Waiting for dirtyDB to parse its file.');
|
|
const dirty = new Database('dirty', `${__dirname}/../var/dirty.db`);
|
|
await dirty.init();
|
|
const keys = await dirty.findKeys('*', '')
|
|
|
|
console.log(`Found ${keys.length} records, processing now.`);
|
|
let numWritten = 0;
|
|
for (const key of keys) {
|
|
const value = await dirty.get(key);
|
|
await db.set(key, value);
|
|
if (++numWritten % 100 === 0) console.log(`Wrote record ${numWritten} of ${keys.length}`);
|
|
}
|
|
console.log(`Wrote all ${numWritten} records`);
|
|
|
|
await db.close();
|
|
await dirty.close();
|
|
console.log('Finished.');
|
|
process.exit(0)
|
|
})();
|