From e24864bde20421f8ee94dd48b2ab0ed89acb971a Mon Sep 17 00:00:00 2001 From: Niek Candaele Date: Wed, 30 Oct 2024 15:06:24 +0100 Subject: [PATCH 1/2] feat: more perf indexes --- .../sql/20241030130613-index-for-roleId.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts diff --git a/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts b/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts new file mode 100644 index 0000000000..63f2734daf --- /dev/null +++ b/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts @@ -0,0 +1,31 @@ +import { Knex } from 'knex'; + +export async function up(knex: Knex): Promise { + await knex.schema.alterTable('permissionOnRole', (table) => { + table.index(['roleId']); + }); + + await knex.schema.alterTable('playerOnGameServer', (table) => { + table.index(['domain', 'playerId']); + }); + + await knex.schema.alterTable('playerInventory', (table) => { + table.dropIndex(['playerId', 'domain']); + table.index(['playerId', 'domain', 'itemId']); + }); +} + +export async function down(knex: Knex): Promise { + await knex.schema.alterTable('permissionOnRole', (table) => { + table.dropIndex(['roleId']); + }); + + await knex.schema.alterTable('playerOnGameServer', (table) => { + table.dropIndex(['domain', 'playerId']); + }); + + await knex.schema.alterTable('playerInventory', (table) => { + table.dropIndex(['domain', 'playerId', 'itemId']); + table.index(['playerId', 'domain']); + }); +} From cd3775fe3e6e4d8efe6d4a374168ffb46f2b4790 Mon Sep 17 00:00:00 2001 From: Niek Candaele Date: Wed, 30 Oct 2024 15:22:12 +0100 Subject: [PATCH 2/2] fix: down migration --- .../src/migrations/sql/20241030130613-index-for-roleId.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts b/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts index 63f2734daf..0214822e44 100644 --- a/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts +++ b/packages/lib-db/src/migrations/sql/20241030130613-index-for-roleId.ts @@ -25,7 +25,7 @@ export async function down(knex: Knex): Promise { }); await knex.schema.alterTable('playerInventory', (table) => { - table.dropIndex(['domain', 'playerId', 'itemId']); + table.dropIndex(['playerId', 'domain', 'itemId']); table.index(['playerId', 'domain']); }); }