diff --git a/ot-node.js b/ot-node.js index b19e788f1..aa9552219 100644 --- a/ot-node.js +++ b/ot-node.js @@ -9,6 +9,7 @@ import { MIN_NODE_VERSION, PARANET_ACCESS_POLICY } from './src/constants/constan import FileService from './src/service/file-service.js'; import OtnodeUpdateCommand from './src/commands/common/otnode-update-command.js'; import OtAutoUpdater from './src/modules/auto-updater/implementation/ot-auto-updater.js'; +import MigrationExecutor from './src/migration/migration-executor.js'; const require = createRequire(import.meta.url); const { setTimeout } = require('timers/promises'); @@ -28,6 +29,12 @@ class OTNode { await this.checkForUpdate(); await this.removeUpdateFile(); + await MigrationExecutor.executeTripleStoreUserConfigurationMigration( + this.container, + this.logger, + this.config, + ); + this.logger.info('██████╗ ██╗ ██╗ ██████╗ ██╗ ██╗ █████╗ '); this.logger.info('██╔══██╗██║ ██╔╝██╔════╝ ██║ ██║██╔══██╗'); this.logger.info('██║ ██║█████╔╝ ██║ ███╗ ██║ ██║╚█████╔╝'); @@ -42,7 +49,6 @@ class OTNode { await this.initializeDependencyContainer(); this.initializeEventEmitter(); - await this.initializeModules(); this.initializeBlockchainEventsService(); await this.initializeShardingTableService(); diff --git a/src/migration/TripleStoreUserConfigurationMigration.js b/src/migration/TripleStoreUserConfigurationMigration.js new file mode 100644 index 000000000..5fef04405 --- /dev/null +++ b/src/migration/TripleStoreUserConfigurationMigration.js @@ -0,0 +1,43 @@ +import appRootPath from 'app-root-path'; +import path from 'path'; +import BaseMigration from './base-migration.js'; + +class TripleStoreUserConfigurationMigration extends BaseMigration { + async executeMigration() { + const configurationFolderPath = path.join(appRootPath.path, '..'); + const configurationFilePath = path.join( + configurationFolderPath, + this.config.configFilename, + ); + + const userConfiguration = await this.fileService.readFile(configurationFilePath, true); + + if ('tripleStore' in userConfiguration.modules) { + const oldConfigTripleStore = userConfiguration.modules; + for (const implementation in oldConfigTripleStore.tripleStore.implementation) { + if (oldConfigTripleStore.tripleStore.implementation[implementation].enabled) { + const { url, username, password } = + oldConfigTripleStore.tripleStore.implementation[implementation].config + .repositories.publicCurrent; + + oldConfigTripleStore.tripleStore.implementation[ + implementation + ].config.repositories.dkg = { + url, + name: 'dkg', + username, + password, + }; + } + } + + await this.fileService.writeContentsToFile( + configurationFolderPath, + this.config.configFilename, + JSON.stringify(userConfiguration, null, 4), + ); + } + } +} + +export default TripleStoreUserConfigurationMigration; diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index aa83c8555..3c6ea53d2 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -1,6 +1,33 @@ import path from 'path'; +import { NODE_ENVIRONMENTS } from '../constants/constants.js'; +import TripleStoreUserConfigurationMigration from './TripleStoreUserConfigurationMigration.js'; + class MigrationExecutor { + static async executeTripleStoreUserConfigurationMigration(container, logger, config) { + if ( + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT || + process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST || + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET + ) + return; + + const migration = new TripleStoreUserConfigurationMigration( + 'tripleStoreUserConfigurationMigration', + logger, + config, + ); + if (!(await migration.migrationAlreadyExecuted())) { + try { + await migration.migrate(); + } catch (error) { + logger.error( + `Unable to execute triple store user configuration migration. Error: ${error.message}`, + ); + } + } + } + static exitNode(code = 0) { process.exit(code); }