Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new migration for removal of service agreements for Chiado Devnet #2897

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading