upgraded prisma to v3.0.2 (#1284)

* upgraded prisma to v3.0.2

* updated queryRaw changes for prisma 3

* queryRaw further changes

* --wip

* --wip

* --WIP

* Preview flag "selectRelationCount" is not needed anymore

* Adds missing migrations

* removed temporary test

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
pull/1366/head^2
Syed Ali Shahbaz 2021-12-21 21:02:16 +05:30 committed by GitHub
parent fbbd7ea45a
commit bab72f1514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 241 deletions

View File

@ -39,7 +39,7 @@
"@hookform/resolvers": "^2.8.3", "@hookform/resolvers": "^2.8.3",
"@jitsu/sdk-js": "^2.2.4", "@jitsu/sdk-js": "^2.2.4",
"@next/bundle-analyzer": "11.1.2", "@next/bundle-analyzer": "11.1.2",
"@prisma/client": "^2.30.2", "@prisma/client": "3.0.2",
"@radix-ui/react-avatar": "^0.1.0", "@radix-ui/react-avatar": "^0.1.0",
"@radix-ui/react-collapsible": "^0.1.0", "@radix-ui/react-collapsible": "^0.1.0",
"@radix-ui/react-dialog": "^0.1.0", "@radix-ui/react-dialog": "^0.1.0",
@ -139,7 +139,7 @@
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"postcss": "^8.4.4", "postcss": "^8.4.4",
"prettier": "^2.3.2", "prettier": "^2.3.2",
"prisma": "^2.30.2", "prisma": "3.0.2",
"tailwindcss": "^3.0.0", "tailwindcss": "^3.0.0",
"ts-jest": "^26.0.0", "ts-jest": "^26.0.0",
"ts-node": "^10.2.1", "ts-node": "^10.2.1",

View File

@ -0,0 +1,74 @@
-- DropForeignKey
ALTER TABLE "EventTypeCustomInput" DROP CONSTRAINT "EventTypeCustomInput_eventTypeId_fkey";
-- DropForeignKey
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_teamId_fkey";
-- DropForeignKey
ALTER TABLE "Membership" DROP CONSTRAINT "Membership_userId_fkey";
-- DropForeignKey
ALTER TABLE "Payment" DROP CONSTRAINT "Payment_bookingId_fkey";
-- DropForeignKey
ALTER TABLE "SelectedCalendar" DROP CONSTRAINT "SelectedCalendar_userId_fkey";
-- DropForeignKey
ALTER TABLE "Webhook" DROP CONSTRAINT "Webhook_userId_fkey";
-- AddForeignKey
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Membership" ADD CONSTRAINT "Membership_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "SelectedCalendar" ADD CONSTRAINT "SelectedCalendar_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "EventTypeCustomInput" ADD CONSTRAINT "EventTypeCustomInput_eventTypeId_fkey" FOREIGN KEY ("eventTypeId") REFERENCES "EventType"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Payment" ADD CONSTRAINT "Payment_bookingId_fkey" FOREIGN KEY ("bookingId") REFERENCES "Booking"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Webhook" ADD CONSTRAINT "Webhook_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- RenameIndex
ALTER INDEX "Booking.uid_unique" RENAME TO "Booking_uid_key";
-- RenameIndex
ALTER INDEX "DestinationCalendar.bookingId_unique" RENAME TO "DestinationCalendar_bookingId_key";
-- RenameIndex
ALTER INDEX "DestinationCalendar.eventTypeId_unique" RENAME TO "DestinationCalendar_eventTypeId_key";
-- RenameIndex
ALTER INDEX "DestinationCalendar.userId_unique" RENAME TO "DestinationCalendar_userId_key";
-- RenameIndex
ALTER INDEX "EventType.userId_slug_unique" RENAME TO "EventType_userId_slug_key";
-- RenameIndex
ALTER INDEX "Payment.externalId_unique" RENAME TO "Payment_externalId_key";
-- RenameIndex
ALTER INDEX "Payment.uid_unique" RENAME TO "Payment_uid_key";
-- RenameIndex
ALTER INDEX "Team.slug_unique" RENAME TO "Team_slug_key";
-- RenameIndex
ALTER INDEX "VerificationRequest.identifier_token_unique" RENAME TO "VerificationRequest_identifier_token_key";
-- RenameIndex
ALTER INDEX "VerificationRequest.token_unique" RENAME TO "VerificationRequest_token_key";
-- RenameIndex
ALTER INDEX "Webhook.id_unique" RENAME TO "Webhook_id_key";
-- RenameIndex
ALTER INDEX "users.email_unique" RENAME TO "users_email_key";
-- RenameIndex
ALTER INDEX "users.username_unique" RENAME TO "users_username_key";

View File

@ -7,8 +7,7 @@ datasource db {
} }
generator client { generator client {
provider = "prisma-client-js" provider = "prisma-client-js"
previewFeatures = ["selectRelationCount"]
} }
enum SchedulingType { enum SchedulingType {

View File

@ -1,219 +0,0 @@
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import fs from "fs";
import prisma from "../lib/prisma";
import { randomString } from "../playwright/lib/testUtils";
dayjs.extend(utc);
dayjs.extend(timezone);
async function tmpMigration() {
// console.log(
// await prisma.$queryRaw(`
// select
// id as "userId",
// CAST(CONCAT(CAST(("startTime") AS text), ' minute')::interval AS time) as "startTime",
// CAST(CONCAT(CAST(("endTime") AS text), ' minute')::interval AS time) as "endTime",
// ARRAY [0,1,2,3,4,5,6]
// from
// (
// select
// users.id,
// users."startTime",
// users."endTime",
// users."timeZone",
// count("Availability".id) as availability_count
// from users
// left join "Availability" on "Availability"."userId" = users.id
// group by users.id
// ) usersWithAvailabilityNumber
// where availability_count < 1
// `)
// );
const MIGRATION_SQL = fs
.readFileSync(__dirname + "/../prisma/migrations/20211115182559_availability_issue/migration.sql")
.toString();
await prisma.$queryRaw(MIGRATION_SQL);
return NaN;
}
afterAll(async () => {
await prisma.$disconnect();
});
test("tmpMigration", async () => {
const ONE_MINUTE_BEFORE_MIDNIGHT = 1440 - 1;
// const unknownTimezoneUser = await prisma.user.create({
// data: {
// name: "unknownTimezoneUser",
// email: `${randomString()}@example.com`,
// startTime: 0, // midnight
// endTime: 1380, // midnight
// timeZone: null,
// },
// });
const europeUser = await prisma.user.create({
data: {
name: "europeanUser0to1380",
email: `${randomString()}@example.com`,
startTime: 0, // midnight
endTime: 1380, // 23:00
timeZone: "Europe/London",
},
});
const americanUser = await prisma.user.create({
data: {
name: "americanUser0toONE_MINUTE_BEFORE_MIDNIGHT",
email: `${randomString()}@example.com`,
startTime: 0, // midnight
endTime: ONE_MINUTE_BEFORE_MIDNIGHT, // midnight
timeZone: "America/Los_Angeles",
},
});
const baseDate = dayjs.utc().set("hour", 0).set("minute", 0).set("second", 0).set("millisecond", 0);
const unaffectedUser = await prisma.user.create({
data: {
email: `${randomString()}@example.com`,
name: "unaffectedUser0toONE_MINUTE_BEFORE_MIDNIGHTu",
startTime: 0, // midnight
endTime: ONE_MINUTE_BEFORE_MIDNIGHT, // midnight
timeZone: "America/Los_Angeles",
availability: {
create: {
startTime: baseDate.add(9, "hour").toDate(),
endTime: baseDate.add(17, "hour").toDate(),
},
},
},
});
const weirdUser = await prisma.user.create({
data: {
email: `${randomString()}@example.com`,
name: "weirdUser",
startTime: 54000,
endTime: 96000,
timeZone: "America/Los_Angeles",
},
});
await tmpMigration();
const users = await prisma.user.findMany({
where: {
id: {
in: [
//
europeUser.id,
americanUser.id,
unaffectedUser.id,
weirdUser.id,
],
},
},
select: {
name: true,
startTime: true,
endTime: true,
timeZone: true,
availability: {
select: {
days: true,
date: true,
startTime: true,
endTime: true,
},
},
},
});
const usersWithNormalizedDates = JSON.parse(JSON.stringify(users));
expect(usersWithNormalizedDates).toMatchInlineSnapshot(`
Array [
Object {
"availability": Array [
Object {
"date": null,
"days": Array [
0,
1,
2,
3,
4,
5,
6,
],
"endTime": "1970-01-01T23:00:00.000Z",
"startTime": "1970-01-01T00:00:00.000Z",
},
],
"endTime": 1380,
"name": "europeanUser0to1380",
"startTime": 0,
"timeZone": "Europe/London",
},
Object {
"availability": Array [
Object {
"date": null,
"days": Array [
0,
1,
2,
3,
4,
5,
6,
],
"endTime": "1970-01-01T23:59:00.000Z",
"startTime": "1970-01-01T00:00:00.000Z",
},
],
"endTime": 1439,
"name": "americanUser0toONE_MINUTE_BEFORE_MIDNIGHT",
"startTime": 0,
"timeZone": "America/Los_Angeles",
},
Object {
"availability": Array [
Object {
"date": null,
"days": Array [],
"endTime": "1970-01-01T17:00:00.000Z",
"startTime": "1970-01-01T09:00:00.000Z",
},
],
"endTime": 1439,
"name": "unaffectedUser0toONE_MINUTE_BEFORE_MIDNIGHTu",
"startTime": 0,
"timeZone": "America/Los_Angeles",
},
Object {
"availability": Array [
Object {
"date": null,
"days": Array [
0,
1,
2,
3,
4,
5,
6,
],
"endTime": "1970-01-01T16:00:00.000Z",
"startTime": "1970-01-01T12:00:00.000Z",
},
],
"endTime": 96000,
"name": "weirdUser",
"startTime": 54000,
"timeZone": "America/Los_Angeles",
},
]
`);
});

View File

@ -1533,22 +1533,22 @@
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1" resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1"
integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g== integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==
"@prisma/client@^2.30.2": "@prisma/client@3.0.2":
version "2.30.3" version "3.0.2"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-2.30.3.tgz#49c1015e2cec26a44b20c62eb2fd738cb0bb043b" resolved "https://registry.yarnpkg.com/@prisma/client/-/client-3.0.2.tgz#f04d9b252f3d0c6918df43ad228eac27d03f6db1"
integrity sha512-Ey2miZ+Hne12We3rA8XrlPoAF0iuKEhw5IK2nropaelSt0Ju3b2qSz9Qt50a/1Mx3+7yRSu/iSXt8y9TUMl/Yw== integrity sha512-6SrDYY2Yr5AmYpVB3XAXFqfzxKMdDTemXR7FmfXthnxWhQHoBwRLNZ3B3GyI/MmWa5tr+kaaGDJjp1LU0vuYvQ==
dependencies: dependencies:
"@prisma/engines-version" "2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20" "@prisma/engines-version" "2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db"
"@prisma/engines-version@2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20": "@prisma/engines-version@2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db":
version "2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20" version "2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20.tgz#d5ef55c92beeba56e52bba12b703af0bfd30530d" resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db.tgz#c45323e420f47dd950b22c873bdcf38f75e65779"
integrity sha512-/iDRgaoSQC77WN2oDsOM8dn61fykm6tnZUAClY+6p+XJbOEgZ9gy4CKuKTBgrjSGDVjtQ/S2KGcYd3Ring8xaw== integrity sha512-iArSApZZImVmT9oC/rGOjzvpG2AOqlIeqYcVnop9poA3FxD4zfVPbNPH9DTgOWhc06OkBHujJZeAcsNddVabIQ==
"@prisma/engines@2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20": "@prisma/engines@2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db":
version "2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20" version "2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20.tgz#2df768aa7c9f84acaa1f35c970417822233a9fb1" resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db.tgz#b6cf70bc05dd2a62168a16f3ea58a1b011074621"
integrity sha512-WPnA/IUrxDihrRhdP6+8KAVSwsc0zsh8ioPYsLJjOhzVhwpRbuFH2tJDRIAbc+qFh+BbTIZbeyBYt8fpNXaYQQ== integrity sha512-Q9CwN6e5E5Abso7J3A1fHbcF4NXGRINyMnf7WQ07fXaebxTTARY5BNUzy2Mo5uH82eRVO5v7ImNuR044KTjLJg==
"@radix-ui/number@0.1.0": "@radix-ui/number@0.1.0":
version "0.1.0" version "0.1.0"
@ -7924,12 +7924,12 @@ pretty-format@^3.8.0:
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-3.8.0.tgz#bfbed56d5e9a776645f4b1ff7aa1a3ac4fa3c385" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-3.8.0.tgz#bfbed56d5e9a776645f4b1ff7aa1a3ac4fa3c385"
integrity sha1-v77VbV6ad2ZF9LH/eqGjrE+jw4U= integrity sha1-v77VbV6ad2ZF9LH/eqGjrE+jw4U=
prisma@^2.30.2: prisma@3.0.2:
version "2.30.3" version "3.0.2"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-2.30.3.tgz#e4a770e1f52151e72c1c5be0aa2e75222a0135c4" resolved "https://registry.yarnpkg.com/prisma/-/prisma-3.0.2.tgz#e86cb6abf4a815c7ac97b9d0ed383f01c253ce34"
integrity sha512-48qYba2BIyUmXuosBZs0g3kYGrxKvo4VkSHYOuLlDdDirmKyvoY2hCYMUYHSx3f++8ovfgs+MX5KmNlP+iAZrQ== integrity sha512-TyOCbtWGDVdWvsM1RhUzJXoGClXGalHhyYWIc5eizSF8T1ScGiOa34asBUdTnXOUBFSErbsqMNw40DHAteBm1A==
dependencies: dependencies:
"@prisma/engines" "2.30.1-2.b8c35d44de987a9691890b3ddf3e2e7effb9bf20" "@prisma/engines" "2.31.0-32.2452cc6313d52b8b9a96999ac0e974d0aedf88db"
process-es6@^0.11.2: process-es6@^0.11.2:
version "0.11.6" version "0.11.6"