Skip to content

Commit

Permalink
Update prisma (#5629)
Browse files Browse the repository at this point in the history
  • Loading branch information
gc authored Feb 22, 2024
1 parent 982591e commit 30728ad
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 42 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ GROUP BY data->>'clueID';`);
select: keysToSelect
});

return result as SelectedUserStats<T>;
return result as unknown as SelectedUserStats<T>;
}

get logName() {
Expand Down
20 changes: 11 additions & 9 deletions src/lib/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/lib/settings/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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++;
});
Expand Down
9 changes: 9 additions & 0 deletions src/lib/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/mahoji/commands/bingo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
4 changes: 2 additions & 2 deletions src/mahoji/lib/abstracted_commands/statCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[]>
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/integration-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
66 changes: 45 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
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/[email protected]":
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/[email protected]":
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/[email protected]":
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/[email protected]":
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 30728ad

Please sign in to comment.