Skip to content

Commit

Permalink
Make migrations non blocking (#3259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic authored Jul 19, 2024
1 parent db5e5ad commit 40ba3c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
12 changes: 6 additions & 6 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ class OTNode {
this.config,
);

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

await this.initializeRouters();
await this.startNetworkModule();
this.startTelemetryModule();
Expand All @@ -96,6 +90,12 @@ class OTNode {
this.config,
);

MigrationExecutor.executeServiceAgreementPruningMigration(
this.container,
this.logger,
this.config,
);

MigrationExecutor.executeRemoveDuplicateServiceAgreementMigration(
this.container,
this.logger,
Expand Down
22 changes: 13 additions & 9 deletions src/migration/remove-duplicate-service-agreement-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ class RemoveDuplicateServiceAgreementMigration extends BaseMigration {
blockchainId,
);
for (const serviceAgreement of findDuplicateServiceAgreements) {
const blockchainAssertionId =
// eslint-disable-next-line no-await-in-loop
await this.blockchainModuleManager.getAssertionIdByIndex(
blockchainId,
serviceAgreement.assetStorageContractAddress,
serviceAgreement.tokenId,
serviceAgreement.stateIndex,
);
if (serviceAgreement.assertionId !== blockchainAssertionId) {
try {
const blockchainAssertionId =
// eslint-disable-next-line no-await-in-loop
await this.blockchainModuleManager.getAssertionIdByIndex(
blockchainId,
serviceAgreement.assetStorageContractAddress,
serviceAgreement.tokenId,
serviceAgreement.stateIndex,
);
if (serviceAgreement.assertionId !== blockchainAssertionId) {
incorrectServiceAgreementId.push(serviceAgreement.agreementId);
}
} catch (error) {
incorrectServiceAgreementId.push(serviceAgreement.agreementId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,10 @@ class ServiceAgreementRepository {
const query = `
DELETE FROM service_agreement
WHERE blockchain_id = '${blockchainId}'
AND asset_storage_contract_address = '${contract}'
AND asset_storage_contract_address != '${contract}'
LIMIT 100000;
`;
await this.model.query(query, {
await this.sequelize.query(query, {
type: Sequelize.QueryTypes.DELETE,
});
}
Expand Down

0 comments on commit 40ba3c9

Please sign in to comment.