From 30728ad8ee312b36f1e9e50a6008fc88639d522b Mon Sep 17 00:00:00 2001 From: GC <30398469+gc@users.noreply.github.com> Date: Fri, 23 Feb 2024 00:35:24 +1100 Subject: [PATCH] Update prisma (#5629) --- package.json | 6 +- src/lib/MUser.ts | 2 +- src/lib/Task.ts | 20 +++--- src/lib/settings/prisma.ts | 9 +-- src/lib/util/logger.ts | 9 +++ src/mahoji/commands/bingo.ts | 2 +- .../lib/abstracted_commands/statCommand.ts | 4 +- src/scripts/integration-tests.ts | 2 +- yarn.lock | 66 +++++++++++++------ 9 files changed, 78 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index b6a6ce96c4..987d69b91a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "wipedist": "rimraf \"dist/\"", "start": "yarn build && concurrently \"tsc -w -p src\" \"node dist/\"", "test": "concurrently \"tsc -p src\" \"yarn test:lint\" \"yarn test:unit\"", - "test:lint": "eslint *.ts \"{src,tests}/**/*.ts\"", + "test:lint": "eslint --quiet *.ts \"{src,tests}/**/*.ts\"", "test:unit": "vitest run --coverage --config vitest.unit.config.ts", "dev": "yarn wipedist && tsc -w -p src", "test:watch": "vitest --config vitest.unit.config.ts --coverage", @@ -24,7 +24,7 @@ "@napi-rs/canvas": "0.1.38", "@octokit/graphql": "^4.8.0", "@oldschoolgg/toolkit": "^0.0.23", - "@prisma/client": "^3.15.1", + "@prisma/client": "^5.10.2", "@sapphire/stopwatch": "^1.4.0", "@sapphire/time-utilities": "^1.6.0", "@sentry/node": "^7.69.0", @@ -84,7 +84,7 @@ "jest-image-snapshot": "^6.2.0", "madge": "^6.0.0", "prettier": "^2.7.1", - "prisma": "^3.15.1", + "prisma": "^5.10.2", "rimraf": "^4.4.0", "source-map-support": "^0.5.21", "ts-node": "^10.9.1", diff --git a/src/lib/MUser.ts b/src/lib/MUser.ts index a7cd714ad8..81044ab1ce 100644 --- a/src/lib/MUser.ts +++ b/src/lib/MUser.ts @@ -699,7 +699,7 @@ GROUP BY data->>'clueID';`); select: keysToSelect }); - return result as SelectedUserStats; + return result as unknown as SelectedUserStats; } get logName() { diff --git a/src/lib/Task.ts b/src/lib/Task.ts index ca03954f17..4fe1ff296d 100644 --- a/src/lib/Task.ts +++ b/src/lib/Task.ts @@ -198,16 +198,18 @@ export async function processPendingActivities() { } }); - await prisma.activity.updateMany({ - where: { - id: { - in: activities.map(i => i.id) + if (activities.length > 0) { + await prisma.activity.updateMany({ + where: { + id: { + in: activities.map(i => i.id) + } + }, + data: { + completed: true } - }, - data: { - completed: true - } - }); + }); + } await Promise.all(activities.map(completeActivity)); return activities; diff --git a/src/lib/settings/prisma.ts b/src/lib/settings/prisma.ts index f52c4bc709..b36b777d15 100644 --- a/src/lib/settings/prisma.ts +++ b/src/lib/settings/prisma.ts @@ -4,6 +4,7 @@ import { Activity, activity_type_enum, Prisma, PrismaClient } from '@prisma/clie import { production } from '../../config'; import { ActivityTaskData } from '../types/minions'; +import { sqlLog } from '../util/logger'; declare global { namespace NodeJS { @@ -29,14 +30,14 @@ function makePrismaClient(): PrismaClient { export const prisma = global.prisma || makePrismaClient(); global.prisma = prisma; -export const prismaQueries: Prisma.QueryEvent[] = []; export let queryCountStore = { value: 0 }; if (isMainThread) { + // @ts-ignore ignore prisma.$on('query' as any, (_query: any) => { - if (!production && globalClient.isReady()) { - const query = _query as Prisma.QueryEvent; - prismaQueries.push(query); + const query = _query as Prisma.QueryEvent; + if (!production) { + sqlLog(query.query); } queryCountStore.value++; }); diff --git a/src/lib/util/logger.ts b/src/lib/util/logger.ts index b239b0daa7..e7b3d91dfa 100644 --- a/src/lib/util/logger.ts +++ b/src/lib/util/logger.ts @@ -17,6 +17,15 @@ export const sonicBoom = new SonicBoom({ sync: false }); +const sqlLogger = new SonicBoom({ + fd: './logs/queries.sql', + mkdir: true, + minLength: 0, + sync: true +}); + +export const sqlLog = (str: string) => sqlLogger.write(`${str}\n`); + interface LogContext { type?: string; [key: string]: unknown; diff --git a/src/mahoji/commands/bingo.ts b/src/mahoji/commands/bingo.ts index 29c6a3b3e7..5f078fe8e2 100644 --- a/src/mahoji/commands/bingo.ts +++ b/src/mahoji/commands/bingo.ts @@ -697,7 +697,7 @@ export const bingoCommand: OSBMahojiCommand = { bingo_tiles: [], creator_id: user.id, guild_id: channel.guildId - } as const; + }; if (createOptions.team_size < 1 || createOptions.team_size > 5) { return 'Team size must be between 1 and 5.'; diff --git a/src/mahoji/lib/abstracted_commands/statCommand.ts b/src/mahoji/lib/abstracted_commands/statCommand.ts index 7b422798cf..2cb942e481 100644 --- a/src/mahoji/lib/abstracted_commands/statCommand.ts +++ b/src/mahoji/lib/abstracted_commands/statCommand.ts @@ -540,9 +540,9 @@ GROUP BY 1;`; await Promise.all( Object.values(SkillsEnum).map( skillName => - prisma.$queryRawUnsafe(`SELECT '${skillName}' as skill_name, COUNT(id) AS qty + prisma.$queryRawUnsafe(`SELECT '${skillName}' as skill_name, COUNT(id)::int AS qty FROM users -WHERE "skills.${skillName}" = 200000000;`) as Promise<{ qty: number; skill_name: string }[]> +WHERE "skills.${skillName}" = 200000000::int;`) as Promise<{ qty: number; skill_name: string }[]> ) ) ) diff --git a/src/scripts/integration-tests.ts b/src/scripts/integration-tests.ts index 39012e8e4a..d1f0202476 100644 --- a/src/scripts/integration-tests.ts +++ b/src/scripts/integration-tests.ts @@ -4,7 +4,7 @@ import { sleep } from 'e'; async function main() { try { execSync('docker compose up -d --wait', { stdio: 'inherit' }); - await sleep(1000); + await sleep(2000); execSync('dotenv -e .env.example -- prisma db push --schema="./prisma/schema.prisma"', { stdio: 'inherit' }); execSync('dotenv -e .env.example -- prisma db push --schema="./prisma/robochimp.prisma"', { stdio: 'inherit' }); diff --git a/yarn.lock b/yarn.lock index 91827bd5d6..27c96784d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,22 +755,46 @@ resolved "https://registry.yarnpkg.com/@oldschoolgg/ts-config/-/ts-config-0.0.1.tgz#53c6244d393548027076537820bbce92ed33e47e" integrity sha512-POoKxMiI10iNjWkk/0sZwxCuXM79dI94tv6Y05KOsLLHL5eVHPZQa+A2gY2pzPf5isDkHwla7i3iOsQglhcKdQ== -"@prisma/client@^3.15.1": - version "3.15.2" - resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.15.2.tgz#2181398147afc79bfe0d83c03a88dc45b49bd365" - integrity sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w== - dependencies: - "@prisma/engines-version" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" - -"@prisma/engines-version@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e": - version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" - resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#bf5e2373ca68ce7556b967cb4965a7095e93fe53" - integrity sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w== - -"@prisma/engines@3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e": - version "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" - resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz#f691893df506b93e3cb1ccc15ec6e5ac64e8e570" - integrity sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg== +"@prisma/client@^5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.10.2.tgz#e087b40a4de8e3171eb9cbf0a873465cd2068e17" + integrity sha512-ef49hzB2yJZCvM5gFHMxSFL9KYrIP9udpT5rYo0CsHD4P9IKj473MbhU1gjKKftiwWBTIyrt9jukprzZXazyag== + +"@prisma/debug@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.10.2.tgz#74be81d8969978f4d53c1b4e76d61f04bfbc3951" + integrity sha512-bkBOmH9dpEBbMKFJj8V+Zp8IZHIBjy3fSyhLhxj4FmKGb/UBSt9doyfA6k1UeUREsMJft7xgPYBbHSOYBr8XCA== + +"@prisma/engines-version@5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9": + version "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9" + resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9.tgz#1502335d4d72d2014cb25b8ad8a740a3a13400ea" + integrity sha512-uCy/++3Jx/O3ufM+qv2H1L4tOemTNqcP/gyEVOlZqTpBvYJUe0tWtW0y3o2Ueq04mll4aM5X3f6ugQftOSLdFQ== + +"@prisma/engines@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.10.2.tgz#a4851d90f76ad6d22e783d5fd2e2e8c0640f1e81" + integrity sha512-HkSJvix6PW8YqEEt3zHfCYYJY69CXsNdhU+wna+4Y7EZ+AwzeupMnUThmvaDA7uqswiHkgm5/SZ6/4CStjaGmw== + dependencies: + "@prisma/debug" "5.10.2" + "@prisma/engines-version" "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9" + "@prisma/fetch-engine" "5.10.2" + "@prisma/get-platform" "5.10.2" + +"@prisma/fetch-engine@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.10.2.tgz#a061f6727d395c7033b55f9c6e92f8741a70d5c5" + integrity sha512-dSmXcqSt6DpTmMaLQ9K8ZKzVAMH3qwGCmYEZr/uVnzVhxRJ1EbT/w2MMwIdBNq1zT69Rvh0h75WMIi0mrIw7Hg== + dependencies: + "@prisma/debug" "5.10.2" + "@prisma/engines-version" "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9" + "@prisma/get-platform" "5.10.2" + +"@prisma/get-platform@5.10.2": + version "5.10.2" + resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.10.2.tgz#7af97b1d82e5574a474e3fbf6eaf04f4156bc535" + integrity sha512-nqXP6vHiY2PIsebBAuDeWiUYg8h8mfjBckHh6Jezuwej0QJNnjDiOq30uesmg+JXxGk99nqyG3B7wpcOODzXvg== + dependencies: + "@prisma/debug" "5.10.2" "@sapphire/async-queue@^1.5.0": version "1.5.0" @@ -4550,12 +4574,12 @@ pretty-ms@^7.0.1: dependencies: parse-ms "^2.1.0" -prisma@^3.15.1: - version "3.15.2" - resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.15.2.tgz#4ebe32fb284da3ac60c49fbc16c75e56ecf32067" - integrity sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA== +prisma@^5.10.2: + version "5.10.2" + resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.10.2.tgz#aa63085c49dc74cdb5c3816e8dd1fb4d74a2aadd" + integrity sha512-hqb/JMz9/kymRE25pMWCxkdyhbnIWrq+h7S6WysJpdnCvhstbJSNP/S6mScEcqiB8Qv2F+0R3yG+osRaWqZacQ== dependencies: - "@prisma/engines" "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" + "@prisma/engines" "5.10.2" process-warning@^2.0.0: version "2.1.0"