Skip to content

Commit 2aa3aa7

Browse files
Park JuhyungPark Juhyung
authored andcommitted
Add indexes for the pendingTx query
1 parent e911289 commit 2aa3aa7

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
const tableName = "Transactions";
4+
module.exports = {
5+
up: async (queryInterface, Sequelize) => {
6+
await queryInterface.addIndex(
7+
tableName,
8+
["isPending", "pendingTimestamp"],
9+
{
10+
where: {
11+
isPending: true
12+
}
13+
}
14+
);
15+
},
16+
17+
down: async (queryInterface, Sequelize) => {
18+
await queryInterface.removeIndex(
19+
tableName,
20+
["isPending", "pendingTimestamp"],
21+
{
22+
where: {
23+
isPending: true
24+
}
25+
}
26+
);
27+
}
28+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use strict";
2+
3+
const tableName = "AddressLogs";
4+
module.exports = {
5+
up: async (queryInterface, Sequelize) => {
6+
await queryInterface.addColumn(tableName, "seq", {
7+
type: Sequelize.INTEGER
8+
});
9+
await queryInterface.addIndex(
10+
tableName,
11+
["isPending", "address", "type", "seq"],
12+
{
13+
where: {
14+
type: "TransactionSigner"
15+
}
16+
}
17+
);
18+
19+
await queryInterface.sequelize.query(
20+
`UPDATE "AddressLogs"
21+
SET "seq" = (SELECT "Transactions"."seq" FROM "Transactions" WHERE hash="AddressLogs"."transactionHash")
22+
WHERE type='TransactionSigner'`
23+
);
24+
},
25+
26+
down: async (queryInterface, Sequelize) => {
27+
await queryInterface.removeIndex(
28+
tableName,
29+
["isPending", "address", "type", "seq"],
30+
{
31+
where: {
32+
type: "TransactionSigner"
33+
}
34+
}
35+
);
36+
await queryInterface.removeColumn(tableName, "seq");
37+
}
38+
};

0 commit comments

Comments
 (0)