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

refactor: cw20/cw721 index and add relation ( develop ) #307

Merged
merged 12 commits into from
Aug 10, 2023
27 changes: 27 additions & 0 deletions migrations/20230809073622_index_cw20_models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('cw20_activity', (table) => {
table.index('from');
table.index('to');
table.index('action');
});
await knex.schema.alterTable('cw721_activity', (table) => {
table.index('from');
table.index('to');
table.index('action');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('cw20_activity', (table) => {
table.dropIndex('from');
table.dropIndex('to');
table.dropIndex('action');
});
await knex.schema.alterTable('cw721_activity', (table) => {
table.dropIndex('from');
table.dropIndex('to');
table.dropIndex('action');
});
}
22 changes: 22 additions & 0 deletions src/models/cw20_activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import BaseModel from './base';
// eslint-disable-next-line import/no-cycle
import { Cw20Contract } from './cw20_contract';
import { SmartContract } from './smart_contract';
import { SmartContractEvent } from './smart_contract_event';
import { Event } from './event';

export class Cw20Event extends BaseModel {
static softDelete = false;
Expand Down Expand Up @@ -70,6 +72,26 @@ export class Cw20Event extends BaseModel {
},
},
},
smart_contract_event: {
relation: Model.BelongsToOneRelation,
modelClass: SmartContractEvent,
join: {
from: 'cw20_activity.smart_contract_event_id',
to: 'smart_contract_event.id',
},
},
event: {
relation: Model.HasOneThroughRelation,
modelClass: Event,
join: {
from: 'cw20_activity.smart_contract_event_id',
to: 'event.id',
through: {
from: 'smart_contract_event.id',
to: 'smart_contract_event.event_id',
},
},
},
};
}
}
13 changes: 13 additions & 0 deletions src/models/cw721_tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BaseModel from './base';
import CW721Contract from './cw721_contract';
import CW721Token from './cw721_token';
import { SmartContractEvent } from './smart_contract_event';
import { Event } from './event';

export default class CW721Activity extends BaseModel {
static softDelete = false;
Expand Down Expand Up @@ -77,6 +78,18 @@ export default class CW721Activity extends BaseModel {
to: 'smart_contract_event.id',
},
},
event: {
relation: Model.HasOneThroughRelation,
modelClass: Event,
join: {
from: 'cw721_activity.smart_contract_event_id',
to: 'event.id',
through: {
from: 'smart_contract_event.id',
to: 'smart_contract_event.event_id',
},
},
},
};
}
}
Loading