Skip to content

Commit

Permalink
Merge pull request #3532 from OriginTrail/v8/migration/triple-store-u…
Browse files Browse the repository at this point in the history
…ser-config-migration

V8/migration/triple store user config migration
  • Loading branch information
Mihajlo-Pavlovic authored Dec 18, 2024
2 parents a9ca5e0 + 46a45e7 commit ac97fcf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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('██║ ██║█████╔╝ ██║ ███╗ ██║ ██║╚█████╔╝');
Expand All @@ -42,7 +49,6 @@ class OTNode {

await this.initializeDependencyContainer();
this.initializeEventEmitter();

await this.initializeModules();
this.initializeBlockchainEventsService();
await this.initializeShardingTableService();
Expand Down
43 changes: 43 additions & 0 deletions src/migration/TripleStoreUserConfigurationMigration.js
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 27 additions & 0 deletions src/migration/migration-executor.js
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down

0 comments on commit ac97fcf

Please sign in to comment.