Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit d22415c

Browse files
committed
refact: migrate old errors save in maria to mongo for gdpr + remove table
1 parent df1d5a4 commit d22415c

7 files changed

Lines changed: 166 additions & 130 deletions

File tree

bun.lock

Lines changed: 92 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,30 @@
4141
"@types/node-cron": "^3.0.11",
4242
"@types/steamapi": "^2.2.5",
4343
"@types/uuid": "^10.0.0",
44-
"prettier": "^3.5.3",
45-
"prisma": "^6.9.0",
44+
"prettier": "^3.6.1",
45+
"prisma": "^6.10.1",
4646
"ts-node": "^10.9.2",
4747
"tsx": "^4.20.3",
4848
"typescript": "^5.8.3"
4949
},
5050
"dependencies": {
51-
"@aws-sdk/client-s3": "^3.828.0",
51+
"@aws-sdk/client-s3": "^3.837.0",
5252
"@discordjs/builders": "^1.11.2",
53-
"@prisma/client": "^6.9.0",
53+
"@prisma/client": "^6.10.1",
5454
"@sentry/cli": "^2.46.0",
5555
"@sentry/core": "^8.55.0",
5656
"@sentry/node": "^8.55.0",
5757
"@sentry/profiling-node": "^8.55.0",
5858
"@types/d3": "^7.4.3",
5959
"@types/jsdom": "^21.1.7",
60-
"@types/node": "^22.15.32",
60+
"@types/node": "^22.15.33",
6161
"archiver": "^7.0.1",
6262
"axios": "^1.10.0",
6363
"body-parser": "^1.20.3",
6464
"cors": "^2.8.5",
6565
"d3": "^7.9.0",
6666
"discord-api-types": "^0.37.120",
67-
"discord.js": "^14.19.3",
67+
"discord.js": "^14.21.0",
6868
"dotenv": "^16.5.0",
6969
"express": "^4.21.2",
7070
"express-useragent": "^1.0.15",
@@ -85,7 +85,7 @@
8585
"unicode-emoji": "^2.6.0",
8686
"uuid": "^9.0.1",
8787
"ws": "^8.18.2",
88-
"zod": "^3.25.64",
88+
"zod": "^3.25.67",
8989
"zod-openapi": "^4.2.4"
9090
}
9191
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `gm_server_errors` table. If the table is not empty, all the data it contains will be lost.
5+
6+
*/
7+
-- DropForeignKey
8+
ALTER TABLE `gm_server_errors` DROP FOREIGN KEY `gm_server_errors_ibfk_1`;
9+
10+
-- AlterTable
11+
ALTER TABLE `banUsers` MODIFY `unbanDate` DATETIME(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP + INTERVAL 2 YEAR);
12+
13+
-- AlterTable
14+
ALTER TABLE `gm_discordToken` MODIFY `expirationDate` DATETIME(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP + INTERVAL 7 DAY);
15+
16+
-- AlterTable
17+
ALTER TABLE `gm_panelToken` MODIFY `expirationDate` DATETIME(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP + INTERVAL 7 DAY);
18+
19+
-- AlterTable
20+
ALTER TABLE `gm_user` MODIFY `token_expires` DATETIME(3) NULL DEFAULT (CURRENT_TIMESTAMP + INTERVAL 7 DAY);
21+
22+
-- AlterTable
23+
ALTER TABLE `gm_users_data_request` MODIFY `expirationDate` DATETIME(3) NOT NULL DEFAULT (CURRENT_TIMESTAMP + INTERVAL 1 DAY);
24+
25+
-- DropTable
26+
DROP TABLE `gm_server_errors`;

prisma/schema.prisma

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ model gm_server {
160160
description String? @default("") @db.VarChar(255)
161161
isPublic Boolean @default(false)
162162
gm_guild gm_guild @relation(fields: [guild], references: [guild], onDelete: Cascade, map: "gm_server_ibfk_1")
163-
gm_server_errors gm_server_errors[]
164163
gm_server_leaderboard_options gm_server_leaderboard_options[]
165164
gm_server_logs_channel gm_server_logs_channel?
166165
gm_server_pseudo gm_server_pseudo[]
@@ -199,24 +198,6 @@ model gm_server_customValues {
199198
updatedAt DateTime @updatedAt
200199
}
201200

202-
model gm_server_errors {
203-
id Int @id @default(autoincrement())
204-
serverID String @db.VarChar(255)
205-
count Int
206-
realm String @db.VarChar(255)
207-
error String @db.Text
208-
stack String @db.Text
209-
name String @db.VarChar(255)
210-
steamID64 String @default("") @db.VarChar(255)
211-
workshopID String @default("") @db.VarChar(255)
212-
uptime Int
213-
createdAt DateTime @default(now())
214-
updatedAt DateTime @updatedAt
215-
gm_server gm_server @relation(fields: [serverID], references: [id], onDelete: Cascade, map: "gm_server_errors_ibfk_1")
216-
217-
@@index([serverID], map: "serverID")
218-
}
219-
220201
model gm_server_leaderboard_options {
221202
serverID String @db.Char(17)
222203
messageID String @db.Char(255)

src/classes/gmod/GmodErrors.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,36 @@ export class GmodErrors {
5050
}
5151
}
5252

53-
export async function getErrorsCountByServer(serverID: string): Promise<number> {
53+
export async function getErrorsCountByServer(serverID: string) {
5454
return await collection.countDocuments({
5555
serverID,
5656
});
5757
}
5858

59+
export async function getErrorsCountBySteamID(steamID64: string) {
60+
return await collection.countDocuments({
61+
steamID64,
62+
});
63+
}
64+
65+
export async function getErrorsBySteamID(steamID64: string, query: Query) {
66+
return {
67+
errors: await collection
68+
.find({
69+
steamID64,
70+
})
71+
.limit(query.limit)
72+
.skip(query.offset)
73+
.toArray(),
74+
query: {
75+
...query,
76+
total: await collection.countDocuments({
77+
steamID64,
78+
}),
79+
},
80+
};
81+
}
82+
5983
export async function getErrorsByServer(query: Query, serverID: string) {
6084
return {
6185
errors: await collection

src/database/gm_server_logs.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { mongoClient } from '../services/mongo/index.js';
22

33
const db = mongoClient.db('gmod_integration');
4-
const collection = db.collection('logs');
4+
const collectionLogs = db.collection('logs');
5+
const collectionErrors = db.collection('errors');
56

67
interface Log {
78
serverID: string;
@@ -13,11 +14,11 @@ interface Log {
1314
}
1415

1516
export async function addLog(log: Log) {
16-
await collection.insertOne(log);
17+
await collectionLogs.insertOne(log);
1718
}
1819

1920
export async function getLogsCountBySteamIDList(SteamIDS: string[]) {
20-
return await collection.countDocuments({
21+
return await collectionLogs.countDocuments({
2122
playerInvolvedSteamID64: {
2223
$in: SteamIDS,
2324
},
@@ -31,7 +32,7 @@ export async function getLogsBySteamIDList(
3132
offset: number | 0;
3233
},
3334
) {
34-
return await collection
35+
return await collectionLogs
3536
.find({
3637
playerInvolvedSteamID64: {
3738
$in: SteamIDS,
@@ -43,7 +44,7 @@ export async function getLogsBySteamIDList(
4344
}
4445

4546
export async function getTotalLogsByServer(serverID: string) {
46-
return await collection.countDocuments({
47+
return await collectionLogs.countDocuments({
4748
serverID,
4849
});
4950
}
@@ -62,7 +63,7 @@ export async function getLogsByServer(
6263
sort: string;
6364
},
6465
) {
65-
return await collection
66+
return await collectionLogs
6667
.find({
6768
serverID,
6869
})

src/models/v3/gdrp.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createBucketIfNotExists, s3 } from '../../services/minio/index.js';
1111
import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
1212
import prisma from '../../services/prisma/index.js';
1313
import { Readable } from 'node:stream';
14+
import { getErrorsBySteamID, getErrorsCountBySteamID } from '../../classes/gmod/GmodErrors.js';
1415

1516
export async function getUserDataGRPD(user: User) {
1617
const discordID = user.getDiscordID();
@@ -124,45 +125,30 @@ export async function getUserDataGRPD(user: User) {
124125
console.error('Error fetching server logs:', error);
125126
}
126127

127-
// Error
128+
// Error logs
128129
try {
129-
const plyErrorsCount = await prisma.gm_server_errors.count({
130-
where: {
131-
steamID64,
132-
},
133-
});
134-
130+
const serverErrorsCount = await getErrorsCountBySteamID(steamID64);
135131
const limit = 1000;
136132
let offset = 0;
137133
let fileIndex = 1;
138-
const totalFiles = Math.ceil(plyErrorsCount / limit);
139-
140-
while (offset < plyErrorsCount) {
141-
const errorLogs = await prisma.gm_server_errors.findMany({
142-
where: {
143-
steamID64,
144-
},
145-
take: limit,
146-
skip: offset,
147-
});
148-
134+
const totalFiles = Math.ceil(serverErrorsCount / limit);
135+
while (offset < serverErrorsCount) {
136+
const errors = await getErrorsBySteamID(steamID64, { limit, offset });
149137
const stream = fs.createWriteStream(`${tempPath}/steam-errors-${fileIndex}-${totalFiles}.json`);
150138

151139
stream.write('[');
152-
for (let i = 0; i < errorLogs.length; i++) {
140+
for (let i = 0; i < errors.errors.length; i++) {
153141
if (i !== 0) stream.write(',');
154-
stream.write(JSON.stringify(errorLogs[i]));
142+
stream.write(JSON.stringify(errors.errors[i]));
155143
}
156144
stream.write(']');
157145
stream.end();
158-
159146
await new Promise<void>((resolve) => stream.on('finish', () => resolve()));
160-
161147
offset += limit;
162148
fileIndex++;
163149
}
164150
} catch (error) {
165-
console.error('Error fetching error logs:', error);
151+
console.error('Error fetching server logs:', error);
166152
}
167153

168154
// Screenshots

0 commit comments

Comments
 (0)