@takaro/db 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare function up(knex: Knex): Promise<void>;
3
+ export declare function down(knex: Knex): Promise<void>;
4
+ //# sourceMappingURL=20250629090822-player-query-performance-indices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20250629090822-player-query-performance-indices.d.ts","sourceRoot":"","sources":["../../../src/migrations/sql/20250629090822-player-query-performance-indices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,wBAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlD;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAWpD"}
@@ -0,0 +1,31 @@
1
+ export async function up(knex) {
2
+ // Create optimized indices for the slow player count query:
3
+ // SELECT COUNT(DISTINCT players.id)
4
+ // FROM players
5
+ // INNER JOIN playerOnGameServer ON playerOnGameServer.playerId = players.id
6
+ // WHERE players.domain = $1 AND playerOnGameServer.lastSeen > $2
7
+ // Primary optimization: Composite index on playerOnGameServer for efficient join + filter
8
+ // This allows PostgreSQL to use the index for both the JOIN and WHERE clause
9
+ await knex.schema.alterTable('playerOnGameServer', (table) => {
10
+ table.index(['playerId', 'lastSeen'], 'idx_playerongameserver_playerid_lastseen');
11
+ });
12
+ // Secondary optimization: Index on players.domain for the WHERE clause
13
+ await knex.schema.alterTable('players', (table) => {
14
+ table.index(['domain'], 'idx_players_domain');
15
+ });
16
+ // Covering index on players(domain, id) to avoid table lookups after index scan
17
+ await knex.schema.alterTable('players', (table) => {
18
+ table.index(['domain', 'id'], 'idx_players_domain_id');
19
+ });
20
+ }
21
+ export async function down(knex) {
22
+ // Drop all indices created in the up function
23
+ await knex.schema.alterTable('playerOnGameServer', (table) => {
24
+ table.dropIndex([], 'idx_playerongameserver_playerid_lastseen');
25
+ });
26
+ await knex.schema.alterTable('players', (table) => {
27
+ table.dropIndex([], 'idx_players_domain');
28
+ table.dropIndex([], 'idx_players_domain_id');
29
+ });
30
+ }
31
+ //# sourceMappingURL=20250629090822-player-query-performance-indices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20250629090822-player-query-performance-indices.js","sourceRoot":"","sources":["../../../src/migrations/sql/20250629090822-player-query-performance-indices.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,4DAA4D;IAC5D,oCAAoC;IACpC,eAAe;IACf,4EAA4E;IAC5E,iEAAiE;IAEjE,0FAA0F;IAC1F,6EAA6E;IAC7E,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3D,KAAK,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,EAAE,0CAA0C,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;IAEH,uEAAuE;IACvE,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QAChD,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,gFAAgF;IAChF,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QAChD,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,uBAAuB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAU;IACnC,8CAA8C;IAE9C,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3D,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QAChD,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,oBAAoB,CAAC,CAAC;QAC1C,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,uBAAuB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takaro/db",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "An opinionated data layer",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -0,0 +1,38 @@
1
+ import { Knex } from 'knex';
2
+
3
+ export async function up(knex: Knex): Promise<void> {
4
+ // Create optimized indices for the slow player count query:
5
+ // SELECT COUNT(DISTINCT players.id)
6
+ // FROM players
7
+ // INNER JOIN playerOnGameServer ON playerOnGameServer.playerId = players.id
8
+ // WHERE players.domain = $1 AND playerOnGameServer.lastSeen > $2
9
+
10
+ // Primary optimization: Composite index on playerOnGameServer for efficient join + filter
11
+ // This allows PostgreSQL to use the index for both the JOIN and WHERE clause
12
+ await knex.schema.alterTable('playerOnGameServer', (table) => {
13
+ table.index(['playerId', 'lastSeen'], 'idx_playerongameserver_playerid_lastseen');
14
+ });
15
+
16
+ // Secondary optimization: Index on players.domain for the WHERE clause
17
+ await knex.schema.alterTable('players', (table) => {
18
+ table.index(['domain'], 'idx_players_domain');
19
+ });
20
+
21
+ // Covering index on players(domain, id) to avoid table lookups after index scan
22
+ await knex.schema.alterTable('players', (table) => {
23
+ table.index(['domain', 'id'], 'idx_players_domain_id');
24
+ });
25
+ }
26
+
27
+ export async function down(knex: Knex): Promise<void> {
28
+ // Drop all indices created in the up function
29
+
30
+ await knex.schema.alterTable('playerOnGameServer', (table) => {
31
+ table.dropIndex([], 'idx_playerongameserver_playerid_lastseen');
32
+ });
33
+
34
+ await knex.schema.alterTable('players', (table) => {
35
+ table.dropIndex([], 'idx_players_domain');
36
+ table.dropIndex([], 'idx_players_domain_id');
37
+ });
38
+ }