Skip to content

Commit

Permalink
add migration output to file
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Nov 13, 2024
1 parent 479ec0e commit ff7061b
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const config = require('../../ts_build/config').default;
const { Storage } = require('../../ts_build');
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
const fs = require('fs');
const os = require('os');

const startDate = new Date('2011-01-01T00:00:00.000Z');
const endDate = new Date();
Expand All @@ -14,6 +16,7 @@ function usage(errMsg) {
console.log(' --oldNetwork <value> REQUIRED - e.g. testnet3');
console.log(' --newNetwork <value> REQUIRED - e.g. testnet4');
console.log(' --doit Save the migration to the db');
console.log(' --out <value> Output file (default: <chain>-<oldNetwork>-<newNetwork>-migrate.json)');
if (errMsg) {
console.log('\nERROR: ' + errMsg);
}
Expand Down Expand Up @@ -44,6 +47,19 @@ if (
usage('Missing required options.');
}

const outIdx = args.indexOf('--out');
let outFile = (outIdx > -1 && args[outIdx + 1]) || `${chain}-${oldNetwork}-${newNetwork}-migrate.json`;

if (outFile.startsWith('~')) {
outFile = outFile.replace('~', os.homedir());
}
if (outFile.startsWith('$HOME')) {
outFile = outFile.replace('$HOME', os.homedir());
}
if (!outFile.startsWith('/') && !outFile.startsWith('./') && !outFile.startsWith('../')) {
outFile = __dirname + '/' + outFile;
}

const doit = args.includes('--doit');

if (!doit) {
Expand Down Expand Up @@ -78,6 +94,7 @@ storage.connect(config.storageOpts, async (err) => {

console.log(` ${doit ? 'REAL:' : 'DRY RUN:'} Found ${Intl.NumberFormat().format(walletCnt)} total wallets to scan`);
console.log(` Migrating ${chain}:${oldNetwork}->${newNetwork}`);
console.log(` Output file: ${outFile}`);
const ans = await new Promise(r => rl.question('Would you like to continue? (y/N): ', r));
if (ans?.toLowerCase() !== 'y') {
return done('Good bye.');
Expand All @@ -94,6 +111,8 @@ storage.connect(config.storageOpts, async (err) => {
continue;
}

fs.appendFileSync(outFile, wallet.id + '\n');

if (doit) {
// Update Wallets collection
const resWallet = await storage.db.collection(Storage.collections.WALLETS).updateMany({
Expand Down

0 comments on commit ff7061b

Please sign in to comment.