Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihajlo-Pavlovic committed Dec 19, 2024
1 parent 7b26f01 commit 3fa4a6b
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 144 deletions.
5 changes: 3 additions & 2 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,16 @@ class OTNode {
continue;
}

const { blockchain, contract, tokenId } = ualService.resolveUAL(paranetUAL);
const { blockchain, contract, knowledgeCollectionId } =
ualService.resolveUAL(paranetUAL);
if (!blockchainModuleManager.getImplementationNames().includes(blockchain)) {
this.logger.warn(
`Unable to initialize Paranet with id ${paranetUAL} because of unsupported blockchain implementation`,
);
continue;
}

const paranetId = paranetService.constructParanetId(contract, tokenId);
const paranetId = paranetService.constructParanetId(contract, knowledgeCollectionId);
// eslint-disable-next-line no-await-in-loop
const paranetExists = await blockchainModuleManager.paranetExists(
blockchain,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,127 +1,101 @@
export async function up({ context: { queryInterface } }) {
await queryInterface.addIndex('shard', ['blockchain_id'], {
name: 'shard_blockchain_id_index',
});

await queryInterface.addIndex('shard', ['last_dialed'], {
name: 'last_dialed_index',
});

await queryInterface.addIndex('service_agreement', ['blockchain_id'], {
name: 'service_agreement_blockchain_id_index',
});

await queryInterface.addIndex('service_agreement', ['blockchain_id', 'token_id'], {
name: 'blockchain_id_token_id_index',
});

await queryInterface.addIndex('service_agreement', ['token_id'], {
name: 'token_id_index',
});

await queryInterface.addIndex('paranet_synced_asset', ['ual'], {
name: 'ual_index',
});

await queryInterface.addIndex('paranet_synced_asset', ['paranet_ual', 'data_source'], {
name: 'paranet_ual_data_source_index',
});

await queryInterface.addIndex('paranet', ['blockchain_id', 'paranet_id'], {
name: 'blockchain_id_paranet_id_index',
});

await queryInterface.addIndex('missed_paranet_asset', ['paranet_ual'], {
name: 'paranet_ual_index',
});

await queryInterface.addIndex('missed_paranet_asset', ['ual'], {
name: 'ual_index',
});

await queryInterface.addIndex('event', ['name', 'timestamp'], {
name: 'name_timestamp_index',
});

await queryInterface.addIndex('event', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('commands', ['name', 'status'], {
name: 'name_status_index',
});

await queryInterface.addIndex('commands', ['status', 'started_at'], {
name: 'status_started_at_index',
});

await queryInterface.addIndex('get', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('publish', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('update', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('publish_paranet', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('get', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('publish', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('update', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('publish_paranet', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('get_response', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('publish_response', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('update_response', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('publish_paranet_response', ['operation_id'], {
name: 'operation_id_index',
});

await queryInterface.addIndex('get_response', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('publish_response', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('update_response', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('publish_paranet_response', ['created_at'], {
name: 'created_at_index',
});

await queryInterface.addIndex('blockchain', ['contract'], {
name: 'contract_index',
});
const indexes = [
{ table: 'shard', column: ['blockchain_id'], name: 'shard_blockchain_id_index' },
{ table: 'shard', column: ['last_dialed'], name: 'last_dialed_index' },
{
table: 'service_agreement',
column: ['blockchain_id'],
name: 'service_agreement_blockchain_id_index',
},
{
table: 'service_agreement',
column: ['blockchain_id', 'token_id'],
name: 'blockchain_id_token_id_index',
},
{ table: 'service_agreement', column: ['token_id'], name: 'token_id_index' },
{ table: 'paranet_synced_asset', column: ['ual'], name: 'paranet_synced_asset_ual_index' },
{
table: 'paranet_synced_asset',
column: ['paranet_ual', 'data_source'],
name: 'paranet_ual_data_source_index',
},
{
table: 'paranet',
column: ['blockchain_id', 'paranet_id'],
name: 'blockchain_id_paranet_id_index',
},
{ table: 'missed_paranet_asset', column: ['paranet_ual'], name: 'paranet_ual_index' },
{ table: 'missed_paranet_asset', column: ['ual'], name: 'missed_paranet_asset_ual_index' },
{ table: 'event', column: ['name', 'timestamp'], name: 'name_timestamp_index' },
{ table: 'event', column: ['operation_id'], name: 'event_operation_id_index' },
{ table: 'commands', column: ['name', 'status'], name: 'name_status_index' },
{ table: 'commands', column: ['status', 'started_at'], name: 'status_started_at_index' },
{ table: 'get', column: ['operation_id'], name: 'get_operation_id_index' },
{ table: 'publish', column: ['operation_id'], name: 'publish_operation_id_index' },
{ table: 'update', column: ['operation_id'], name: 'update_operation_id_index' },
{
table: 'publish_paranet',
column: ['operation_id'],
name: 'publish_paranet_operation_id_index',
},
{ table: 'get', column: ['created_at'], name: 'get_created_at_index' },
{ table: 'publish', column: ['created_at'], name: 'publish_created_at_index' },
{ table: 'update', column: ['created_at'], name: 'update_created_at_index' },
{
table: 'publish_paranet',
column: ['created_at'],
name: 'publish_paranet_created_at_index',
},
{
table: 'get_response',
column: ['operation_id'],
name: 'get_response_operation_id_index',
},
{ table: 'publish_response', column: ['operation_id'], name: 'operation_id_index' },
{
table: 'update_response',
column: ['operation_id'],
name: 'update_response_operation_id_index',
},
{
table: 'publish_paranet_response',
column: ['operation_id'],
name: 'publish_paranet_response_operation_id_index',
},
{ table: 'get_response', column: ['created_at'], name: 'get_response_created_at_index' },
{
table: 'publish_response',
column: ['created_at'],
name: 'publish_response_created_at_index',
},
{
table: 'update_response',
column: ['created_at'],
name: 'update_response_created_at_index',
},
{
table: 'publish_paranet_response',
column: ['created_at'],
name: 'publish_paranet_response_created_at_index',
},
{ table: 'blockchain', column: ['contract'], name: 'contract_index' },
];

for (const index of indexes) {
const { table, column, name } = index;

// eslint-disable-next-line no-await-in-loop
const [results] = await queryInterface.sequelize.query(`
SELECT COUNT(1) AS count
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '${table}' AND INDEX_NAME = '${name}';
`);

if (results[0].count === 0) {
// eslint-disable-next-line no-await-in-loop
await queryInterface.addIndex(table, column, { name });
}
}
}

export async function down({ context: { queryInterface } }) {
Expand All @@ -135,55 +109,61 @@ export async function down({ context: { queryInterface } }) {

await queryInterface.removeIndex('service_agreement', 'token_id_index');

await queryInterface.removeIndex('paranet_synced_asset', 'ual_index');
await queryInterface.removeIndex('paranet_synced_asset', 'paranet_synced_asset_ual_index');

await queryInterface.removeIndex('paranet_synced_asset', 'paranet_ual_data_source_index');

await queryInterface.removeIndex('paranet', 'blockchain_id_paranet_id_index');

await queryInterface.removeIndex('missed_paranet_asset', 'paranet_ual_index');

await queryInterface.removeIndex('missed_paranet_asset', 'ual_index');
await queryInterface.removeIndex('missed_paranet_asset', 'missed_paranet_asset_ual_index');

await queryInterface.removeIndex('event', 'name_timestamp_index');

await queryInterface.removeIndex('event', 'operation_id_index');
await queryInterface.removeIndex('event', 'event_operation_id_index');

await queryInterface.removeIndex('commands', 'name_status_index');

await queryInterface.removeIndex('commands', 'status_started_at_index');

await queryInterface.removeIndex('get', 'operation_id_index');
await queryInterface.removeIndex('get', 'get_operation_id_index');

await queryInterface.removeIndex('publish', 'operation_id_index');
await queryInterface.removeIndex('publish', 'publish_operation_id_index');

await queryInterface.removeIndex('update', 'operation_id_index');
await queryInterface.removeIndex('update', 'update_operation_id_index');

await queryInterface.removeIndex('publish_paranet', 'operation_id_index');
await queryInterface.removeIndex('publish_paranet', 'publish_paranet_operation_id_index');

await queryInterface.removeIndex('get', 'created_at_index');
await queryInterface.removeIndex('get', 'get_created_at_index');

await queryInterface.removeIndex('publish', 'created_at_index');
await queryInterface.removeIndex('publish', 'publish_created_at_index');

await queryInterface.removeIndex('update', 'created_at_index');
await queryInterface.removeIndex('update', 'update_created_at_index');

await queryInterface.removeIndex('publish_paranet', 'created_at_index');
await queryInterface.removeIndex('publish_paranet', 'publish_paranet_created_at_index');

await queryInterface.removeIndex('get_response', 'operation_id_index');
await queryInterface.removeIndex('get_response', 'get_response_operation_id_index');

await queryInterface.removeIndex('publish_response', 'operation_id_index');
await queryInterface.removeIndex('publish_response', 'publish_response_operation_id_index');

await queryInterface.removeIndex('update_response', 'operation_id_index');
await queryInterface.removeIndex('update_response', 'update_response_operation_id_index');

await queryInterface.removeIndex('publish_paranet_response', 'operation_id_index');
await queryInterface.removeIndex(
'publish_paranet_response',
'publish_paranet_response_operation_id_index',
);

await queryInterface.removeIndex('get_response', 'created_at_index');
await queryInterface.removeIndex('get_response', 'get_response_created_at_index');

await queryInterface.removeIndex('publish_response', 'created_at_index');
await queryInterface.removeIndex('publish_response', 'publish_response_created_at_index');

await queryInterface.removeIndex('update_response', 'created_at_index');
await queryInterface.removeIndex('update_response', 'update_response_created_at_index');

await queryInterface.removeIndex('publish_paranet_response', 'created_at_index');
await queryInterface.removeIndex(
'publish_paranet_response',
'publish_paranet_response_created_at_index',
);

await queryInterface.removeIndex('blockchain', 'contract_index');
}

0 comments on commit 3fa4a6b

Please sign in to comment.