add indexes

This commit is contained in:
jejolare 2026-03-14 15:38:03 +07:00
parent 4c2a01e5cb
commit c68aaae044
5 changed files with 57 additions and 0 deletions

View file

@ -51,6 +51,7 @@
"import/prefer-default-export": "off", "import/prefer-default-export": "off",
"import/no-cycle": "off" "import/no-cycle": "off"
}, },
"ignorePatterns": ["migrations/**/*.cjs"],
"settings": { "settings": {
"import/resolver": { "import/resolver": {
"node": { "node": {

View file

@ -0,0 +1,25 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
await queryInterface.addIndex('Orders', ['pair_id', 'type', 'status', 'price'], {
name: 'orders_pair_id_type_status_price',
});
await queryInterface.addIndex('Orders', ['pair_id'], {
name: 'orders_pair_id',
});
await queryInterface.addIndex('Orders', ['user_id'], {
name: 'orders_user_id',
});
await queryInterface.addIndex('Orders', ['timestamp'], {
name: 'orders_timestamp',
});
},
async down(queryInterface) {
await queryInterface.removeIndex('Orders', 'orders_pair_id_type_status_price');
await queryInterface.removeIndex('Orders', 'orders_pair_id');
await queryInterface.removeIndex('Orders', 'orders_user_id');
await queryInterface.removeIndex('Orders', 'orders_timestamp');
},
};

View file

@ -0,0 +1,20 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
await queryInterface.addIndex('Transactions', ['buy_order_id', 'status'], {
name: 'transactions_buy_order_id_status',
});
await queryInterface.addIndex('Transactions', ['sell_order_id', 'status'], {
name: 'transactions_sell_order_id_status',
});
await queryInterface.addIndex('Transactions', ['timestamp'], {
name: 'transactions_timestamp',
});
},
async down(queryInterface) {
await queryInterface.removeIndex('Transactions', 'transactions_buy_order_id_status');
await queryInterface.removeIndex('Transactions', 'transactions_sell_order_id_status');
await queryInterface.removeIndex('Transactions', 'transactions_timestamp');
},
};

View file

@ -101,6 +101,12 @@ Order.init(
sequelize, sequelize,
modelName: 'Order', modelName: 'Order',
timestamps: true, timestamps: true,
indexes: [
{ fields: ['pair_id', 'type', 'status', 'price'] },
{ fields: ['pair_id'] },
{ fields: ['user_id'] },
{ fields: ['timestamp'] },
],
}, },
); );

View file

@ -59,6 +59,11 @@ Transaction.init(
sequelize, sequelize,
modelName: 'Transaction', modelName: 'Transaction',
timestamps: true, timestamps: true,
indexes: [
{ fields: ['buy_order_id', 'status'] },
{ fields: ['sell_order_id', 'status'] },
{ fields: ['timestamp'] },
],
}, },
); );