diff --git a/v8-data-migration/constants.js b/v8-data-migration/constants.js index ea657bff9..9395ea218 100644 --- a/v8-data-migration/constants.js +++ b/v8-data-migration/constants.js @@ -23,9 +23,15 @@ export const BATCH_SIZE = 50; // export const NODERC_CONFIG_PATH = // '/Users/zvonimir/projects/ot-node/v8-data-migration/.origintrail_noderc'; // export const ENV_PATH = '/Users/zvonimir/projects/ot-node/data-migration/.env'; +// export const DEFAULT_CONFIG_PATH = '/Users/zvonimir/projects/ot-node/config/config.json'; +// export const DATA_MIGRATION_DIR = +// '/Users/zvonimir/projects/ot-node/v8-data-migration/data/data-migration'; +// export const MIGRATION_PROGRESS_FILE = +// '/Users/zvonimir/projects/ot-node/v8-data-migration/data/migrations/v8DataMigration'; // // LOCAL TESTING END // REMOTE +export const DEFAULT_CONFIG_PATH = '/root/ot-node/current/config/config.json'; export const NODERC_CONFIG_PATH = '/root/ot-node/.origintrail_noderc'; export const DATA_MIGRATION_DIR = '/root/ot-node/data/data-migration'; export const ENV_PATH = '/root/ot-node/current/.env'; diff --git a/v8-data-migration/v8-data-migration-utils.js b/v8-data-migration/v8-data-migration-utils.js index dd31af2df..a3f88c4c4 100644 --- a/v8-data-migration/v8-data-migration-utils.js +++ b/v8-data-migration/v8-data-migration-utils.js @@ -3,7 +3,7 @@ import path from 'path'; import { stringify } from 'csv-stringify'; import { parse as csvParse } from 'csv-parse'; import readLastLines from 'read-last-lines'; -import { NODERC_CONFIG_PATH, MIGRATION_PROGRESS_FILE } from './constants.js'; +import { NODERC_CONFIG_PATH, MIGRATION_PROGRESS_FILE, DEFAULT_CONFIG_PATH } from './constants.js'; import { validateSuccessfulInserts, validateConfig } from './validation.js'; import logger from './logger.js'; @@ -14,6 +14,13 @@ export function initializeConfig() { return config; } +export function initializeDefaultConfig() { + const configPath = path.resolve(DEFAULT_CONFIG_PATH); + const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + validateConfig(config); + return config; +} + export async function getHighestTokenId(csvFilePath) { try { const lastLine = await readLastLines.read(csvFilePath, 1); // Read the last line diff --git a/v8-data-migration/v8-data-migration.js b/v8-data-migration/v8-data-migration.js index 127298a0e..52e3e88a6 100644 --- a/v8-data-migration/v8-data-migration.js +++ b/v8-data-migration/v8-data-migration.js @@ -13,6 +13,7 @@ import { import { updateCsvFile, initializeConfig, + initializeDefaultConfig, getCsvDataStream, getHighestTokenId, ensureDirectoryExists, @@ -239,9 +240,12 @@ async function main() { ensureDirectoryExists(DATA_MIGRATION_DIR); // REMOTE END - // initialize node config + // initialize noderc config const config = initializeConfig(); + // initialize default config + const defaultConfig = initializeDefaultConfig(); + // Initialize blockchain config const blockchainConfig = config.modules.blockchain; if (!blockchainConfig || !blockchainConfig.implementation) { @@ -291,7 +295,10 @@ async function main() { logger.info(`Blockchain ${blockchain} is not enabled. Skipping...`); continue; } - const rpcEndpoints = blockchainImplementation?.config?.rpcEndpoints; + const rpcEndpoints = blockchainImplementation?.config?.rpcEndpoints + ? blockchainImplementation.config.rpcEndpoints + : defaultConfig[process.env.NODE_ENV].modules.blockchain.implementation[blockchain] + .config.rpcEndpoints; if (!Array.isArray(rpcEndpoints) || rpcEndpoints.length === 0) { throw new Error(`RPC endpoints are not defined for blockchain ${blockchain}.`); }