Skip to content

Commit

Permalink
Merge pull request #2897 from OriginTrail/v6/feature/remove-service-a…
Browse files Browse the repository at this point in the history
…greements-for-chiado-devnet

Added new migration for removal of service agreements for Chiado Devnet
  • Loading branch information
djordjekovac authored Jan 25, 2024
2 parents 6e56349 + c14ecf8 commit bdaaeca
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class OTNode {

await this.initializeModules();

await MigrationExecutor.executeRemoveServiceAgreementsForChiadoDevnetMigration(
this.container,
this.logger,
this.config,
);

await this.createProfiles();

await this.initializeCommandExecutor();
Expand Down
24 changes: 24 additions & 0 deletions src/migration/migration-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ServiceAgreementsInvalidDataMigration from './service-agreements-invalid-
import UalExtensionUserConfigurationMigration from './ual-extension-user-configuration-migration.js';
import UalExtensionTripleStoreMigration from './ual-extension-triple-store-migration.js';
import MarkStakingEventsAsProcessedMigration from './mark-staking-events-as-processed-migration.js';
import RemoveServiceAgreementsForChiadoDevnetMigration from './remove-service-agreements-for-chiado-devnet-migration.js';

class MigrationExecutor {
static async executePullShardingTableMigration(container, logger, config) {
Expand Down Expand Up @@ -364,6 +365,29 @@ class MigrationExecutor {
}
}

static async executeRemoveServiceAgreementsForChiadoDevnetMigration(container, logger, config) {
if (process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVNET) {
const repositoryModuleManager = container.resolve('repositoryModuleManager');

const migration = new RemoveServiceAgreementsForChiadoDevnetMigration(
'removeServiceAgreementsForChiadoDevnetMigration',
logger,
config,
repositoryModuleManager,
);
if (!(await migration.migrationAlreadyExecuted())) {
try {
await migration.migrate();
} catch (error) {
logger.error(
`Unable to execute remove service agreements for Chiado Devnet migration. Error: ${error.message}`,
);
this.exitNode(1);
}
}
}
}

static exitNode(code = 0) {
process.exit(code);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import BaseMigration from './base-migration.js';

const GNOSIS_DEVNET_CHAIN_ID = 'gnosis:10200';

class RemoveServiceAgreementsForChiadoDevnetMigration extends BaseMigration {
constructor(migrationName, logger, config, repositoryModuleManager) {
super(migrationName, logger, config);
this.repositoryModuleManager = repositoryModuleManager;
}

async executeMigration() {
await this.repositoryModuleManager.removeServiceAgreementsForBlockchain(
GNOSIS_DEVNET_CHAIN_ID,
);
}
}

export default RemoveServiceAgreementsForChiadoDevnetMigration;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class ServiceAgreementRepository {
});
}

async removeServiceAgreementsForBlockchain(blockchainId) {
await this.model.destroy({
where: {
blockchainId,
},
});
}

async updateServiceAgreementRecord(
blockchainId,
assetStorageContractAddress,
Expand Down
6 changes: 6 additions & 0 deletions src/modules/repository/repository-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ class RepositoryModuleManager extends BaseModuleManager {
return this.getRepository('service_agreement').removeServiceAgreements(agreementIds);
}

async removeServiceAgreementsForBlockchain(blockchainId) {
return this.getRepository('service_agreement').removeServiceAgreementsForBlockchain(
blockchainId,
);
}

async updateServiceAgreementEpochsNumber(agreementId, epochsNumber) {
return this.getRepository('service_agreement').updateServiceAgreementEpochsNumber(
agreementId,
Expand Down

0 comments on commit bdaaeca

Please sign in to comment.