@takaro/db 0.4.8 → 0.4.10
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.
- package/dist/migrations/sql/20251108214824-unique-player-per-server.d.ts +4 -0
- package/dist/migrations/sql/20251108214824-unique-player-per-server.d.ts.map +1 -0
- package/dist/migrations/sql/20251108214824-unique-player-per-server.js +27 -0
- package/dist/migrations/sql/20251108214824-unique-player-per-server.js.map +1 -0
- package/package.json +1 -1
- package/src/migrations/sql/20251108214824-unique-player-per-server.ts +30 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20251108214824-unique-player-per-server.d.ts","sourceRoot":"","sources":["../../../src/migrations/sql/20251108214824-unique-player-per-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,wBAAsB,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBlD;AAED,wBAAsB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export async function up(knex) {
|
|
2
|
+
// Delete duplicate rows where the same playerId has multiple different gameIds on the same server
|
|
3
|
+
// This violates the business rule that each player should have exactly one POG per server
|
|
4
|
+
// Keep the oldest POG (lowest id) for each (playerId, gameServerId) pair
|
|
5
|
+
await knex.raw(`
|
|
6
|
+
DELETE FROM "playerOnGameServer"
|
|
7
|
+
WHERE id IN (
|
|
8
|
+
SELECT id
|
|
9
|
+
FROM (
|
|
10
|
+
SELECT id,
|
|
11
|
+
ROW_NUMBER() OVER (PARTITION BY "playerId", "gameServerId" ORDER BY id) as rnk
|
|
12
|
+
FROM "playerOnGameServer"
|
|
13
|
+
) t
|
|
14
|
+
WHERE t.rnk > 1
|
|
15
|
+
)
|
|
16
|
+
`);
|
|
17
|
+
// Add unique constraint to prevent one player from having multiple POGs on the same server
|
|
18
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
19
|
+
table.unique(['playerId', 'gameServerId']);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export async function down(knex) {
|
|
23
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
24
|
+
table.dropUnique(['playerId', 'gameServerId']);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=20251108214824-unique-player-per-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20251108214824-unique-player-per-server.js","sourceRoot":"","sources":["../../../src/migrations/sql/20251108214824-unique-player-per-server.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,IAAU;IACjC,kGAAkG;IAClG,0FAA0F;IAC1F,yEAAyE;IACzE,MAAM,IAAI,CAAC,GAAG,CAAC;;;;;;;;;;;GAWd,CAAC,CAAC;IAEH,2FAA2F;IAC3F,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3D,KAAK,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAU;IACnC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;QAC3D,KAAK,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
|
|
3
|
+
export async function up(knex: Knex): Promise<void> {
|
|
4
|
+
// Delete duplicate rows where the same playerId has multiple different gameIds on the same server
|
|
5
|
+
// This violates the business rule that each player should have exactly one POG per server
|
|
6
|
+
// Keep the oldest POG (lowest id) for each (playerId, gameServerId) pair
|
|
7
|
+
await knex.raw(`
|
|
8
|
+
DELETE FROM "playerOnGameServer"
|
|
9
|
+
WHERE id IN (
|
|
10
|
+
SELECT id
|
|
11
|
+
FROM (
|
|
12
|
+
SELECT id,
|
|
13
|
+
ROW_NUMBER() OVER (PARTITION BY "playerId", "gameServerId" ORDER BY id) as rnk
|
|
14
|
+
FROM "playerOnGameServer"
|
|
15
|
+
) t
|
|
16
|
+
WHERE t.rnk > 1
|
|
17
|
+
)
|
|
18
|
+
`);
|
|
19
|
+
|
|
20
|
+
// Add unique constraint to prevent one player from having multiple POGs on the same server
|
|
21
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
22
|
+
table.unique(['playerId', 'gameServerId']);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function down(knex: Knex): Promise<void> {
|
|
27
|
+
await knex.schema.alterTable('playerOnGameServer', (table) => {
|
|
28
|
+
table.dropUnique(['playerId', 'gameServerId']);
|
|
29
|
+
});
|
|
30
|
+
}
|