From c68aaae044a63c2260d34eee182009e4d616dd79 Mon Sep 17 00:00:00 2001 From: jejolare Date: Sat, 14 Mar 2026 15:38:03 +0700 Subject: [PATCH] add indexes --- .eslintrc.json | 1 + .../20260314153308-add-orders-indexes.cjs | 25 +++++++++++++++++++ ...0260314153309-add-transactions-indexes.cjs | 20 +++++++++++++++ src/schemes/Order.ts | 6 +++++ src/schemes/Transaction.ts | 5 ++++ 5 files changed, 57 insertions(+) create mode 100644 migrations/20260314153308-add-orders-indexes.cjs create mode 100644 migrations/20260314153309-add-transactions-indexes.cjs diff --git a/.eslintrc.json b/.eslintrc.json index dffaf9c..bbf800c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -51,6 +51,7 @@ "import/prefer-default-export": "off", "import/no-cycle": "off" }, + "ignorePatterns": ["migrations/**/*.cjs"], "settings": { "import/resolver": { "node": { diff --git a/migrations/20260314153308-add-orders-indexes.cjs b/migrations/20260314153308-add-orders-indexes.cjs new file mode 100644 index 0000000..11568f4 --- /dev/null +++ b/migrations/20260314153308-add-orders-indexes.cjs @@ -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'); + }, +}; diff --git a/migrations/20260314153309-add-transactions-indexes.cjs b/migrations/20260314153309-add-transactions-indexes.cjs new file mode 100644 index 0000000..cfb6d3a --- /dev/null +++ b/migrations/20260314153309-add-transactions-indexes.cjs @@ -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'); + }, +}; diff --git a/src/schemes/Order.ts b/src/schemes/Order.ts index 00de457..91e63a7 100644 --- a/src/schemes/Order.ts +++ b/src/schemes/Order.ts @@ -101,6 +101,12 @@ Order.init( sequelize, modelName: 'Order', timestamps: true, + indexes: [ + { fields: ['pair_id', 'type', 'status', 'price'] }, + { fields: ['pair_id'] }, + { fields: ['user_id'] }, + { fields: ['timestamp'] }, + ], }, ); diff --git a/src/schemes/Transaction.ts b/src/schemes/Transaction.ts index f9a7547..1d70d72 100644 --- a/src/schemes/Transaction.ts +++ b/src/schemes/Transaction.ts @@ -59,6 +59,11 @@ Transaction.init( sequelize, modelName: 'Transaction', timestamps: true, + indexes: [ + { fields: ['buy_order_id', 'status'] }, + { fields: ['sell_order_id', 'status'] }, + { fields: ['timestamp'] }, + ], }, );