From 86b32daaafea006b6783242597235dff6a2dc9f7 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Tue, 17 Dec 2024 19:51:00 +0100 Subject: [PATCH 1/3] Add triple store config migration --- ot-node.js | 8 ++++- .../TripleStoreUserConfigurationMigration.js | 35 +++++++++++++++++++ src/migration/migration-executor.js | 26 ++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/migration/TripleStoreUserConfigurationMigration.js 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..12e9679a1 --- /dev/null +++ b/src/migration/TripleStoreUserConfigurationMigration.js @@ -0,0 +1,35 @@ +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) { + const oldConfigTripleStore = userConfiguration.modules; + const implementation = oldConfigTripleStore.implementation[0]; + const { url, username, password } = implementation.config.repositories.publicCurrent; + 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..a83892690 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -1,6 +1,32 @@ import path from 'path'; +import { NODE_ENVIRONMENTS } from '../constants/constants.js'; +import TripleStoreUserConfigurationMigration from './TripleStoreUserConfigurationMigration'; + class MigrationExecutor { + static async executeTripleStoreUserConfigurationMigration(container, logger, config) { + if ( + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT || + process.env.NODE_ENV === NODE_ENVIRONMENTS.TEST + ) + 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); } From 703a3c01014ef6fd3d40758359f329ac890a49cf Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Tue, 17 Dec 2024 20:12:13 +0100 Subject: [PATCH 2/3] migration testest --- .../TripleStoreUserConfigurationMigration.js | 26 ++++++++++++------- src/migration/migration-executor.js | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/migration/TripleStoreUserConfigurationMigration.js b/src/migration/TripleStoreUserConfigurationMigration.js index 12e9679a1..5fef04405 100644 --- a/src/migration/TripleStoreUserConfigurationMigration.js +++ b/src/migration/TripleStoreUserConfigurationMigration.js @@ -12,16 +12,24 @@ class TripleStoreUserConfigurationMigration extends BaseMigration { const userConfiguration = await this.fileService.readFile(configurationFilePath, true); - if ('tripleStore' in userConfiguration) { + if ('tripleStore' in userConfiguration.modules) { const oldConfigTripleStore = userConfiguration.modules; - const implementation = oldConfigTripleStore.implementation[0]; - const { url, username, password } = implementation.config.repositories.publicCurrent; - implementation.config.repositories.dkg = { - url, - name: 'dkg', - username, - password, - }; + 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, diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index a83892690..df1897a44 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -1,7 +1,7 @@ import path from 'path'; import { NODE_ENVIRONMENTS } from '../constants/constants.js'; -import TripleStoreUserConfigurationMigration from './TripleStoreUserConfigurationMigration'; +import TripleStoreUserConfigurationMigration from './TripleStoreUserConfigurationMigration.js'; class MigrationExecutor { static async executeTripleStoreUserConfigurationMigration(container, logger, config) { From 46a45e71fa872f58f6eb3e02c92c83ef4f40cab3 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Tue, 17 Dec 2024 20:12:53 +0100 Subject: [PATCH 3/3] disable migration for devnet --- src/migration/migration-executor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/migration/migration-executor.js b/src/migration/migration-executor.js index df1897a44..3c6ea53d2 100644 --- a/src/migration/migration-executor.js +++ b/src/migration/migration-executor.js @@ -7,7 +7,8 @@ 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.TEST || + process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET ) return;