From 3d6bb570d9c15708e3f4a882e4f4f995c429f6f3 Mon Sep 17 00:00:00 2001 From: hbjORbj Date: Wed, 27 Nov 2024 05:32:03 -0500 Subject: [PATCH 1/2] chore: drop sourceLang, targetLang and id columns --- .../tasks/translateEventTypeDescription.ts | 3 -- .../server/repository/eventTypeTranslation.ts | 24 ++++---------- .../migration.sql | 33 +++++++++++++++++++ packages/prisma/schema.prisma | 7 +--- 4 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql diff --git a/packages/features/tasker/tasks/translateEventTypeDescription.ts b/packages/features/tasker/tasks/translateEventTypeDescription.ts index e1c4a492200d98..900d1d437e0e7c 100644 --- a/packages/features/tasker/tasks/translateEventTypeDescription.ts +++ b/packages/features/tasker/tasks/translateEventTypeDescription.ts @@ -63,9 +63,6 @@ export async function translateEventTypeDescription(payload: string): Promise) { return await Promise.all( translations.map(({ userId, ...translation }) => { - const whereClause = translation.targetLang // TODO: remove after migration - ? { - eventTypeId_field_targetLang: { - eventTypeId: translation.eventTypeId, - field: EventTypeAutoTranslatedField.DESCRIPTION, - targetLang: translation.targetLang, - }, - } - : { - eventTypeId_field_targetLocale: { - eventTypeId: translation.eventTypeId, - field: EventTypeAutoTranslatedField.DESCRIPTION, - targetLocale: translation.targetLocale, - }, - }; return prisma.eventTypeTranslation.upsert({ - where: whereClause, + where: { + eventTypeId_field_targetLocale: { + eventTypeId: translation.eventTypeId, + field: EventTypeAutoTranslatedField.DESCRIPTION, + targetLocale: translation.targetLocale, + }, + }, update: { translatedText: translation.translatedText, updatedBy: userId, diff --git a/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql b/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql new file mode 100644 index 00000000000000..fd06846aa80e92 --- /dev/null +++ b/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql @@ -0,0 +1,33 @@ +/* + Warnings: + + - The primary key for the `EventTypeTranslation` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `id` on the `EventTypeTranslation` table. All the data in the column will be lost. + - You are about to drop the column `sourceLang` on the `EventTypeTranslation` table. All the data in the column will be lost. + - You are about to drop the column `targetLang` on the `EventTypeTranslation` table. All the data in the column will be lost. + - Made the column `uid` on table `EventTypeTranslation` required. This step will fail if there are existing NULL values in that column. + +*/ + +-- Copy data +UPDATE "EventTypeTranslation" SET + "sourceLocale" = "sourceLang", + "targetLocale" = "targetLang"; + +-- Copy data +UPDATE "EventTypeTranslation" SET + "uid" = "id"; + +-- DropIndex +DROP INDEX "EventTypeTranslation_eventTypeId_field_targetLang_idx"; + +-- DropIndex +DROP INDEX "EventTypeTranslation_eventTypeId_field_targetLang_key"; + +-- AlterTable +ALTER TABLE "EventTypeTranslation" DROP CONSTRAINT "EventTypeTranslation_pkey", +DROP COLUMN "id", +DROP COLUMN "sourceLang", +DROP COLUMN "targetLang", +ALTER COLUMN "uid" SET NOT NULL, +ADD CONSTRAINT "EventTypeTranslation_pkey" PRIMARY KEY ("uid"); diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prisma index 4b4bbc5c606f93..a39753409931e9 100644 --- a/packages/prisma/schema.prisma +++ b/packages/prisma/schema.prisma @@ -1633,13 +1633,10 @@ enum EventTypeAutoTranslatedField { } model EventTypeTranslation { - id String @id @default(cuid()) - uid String? + uid String @id @default(cuid()) eventType EventType @relation(fields: [eventTypeId], references: [id], onDelete: Cascade) eventTypeId Int field EventTypeAutoTranslatedField - sourceLang String - targetLang String sourceLocale String targetLocale String translatedText String @db.Text @@ -1650,8 +1647,6 @@ model EventTypeTranslation { creator User @relation("CreatedEventTypeTranslations", fields: [createdBy], references: [id]) updater User? @relation("UpdatedEventTypeTranslations", fields: [updatedBy], references: [id], onDelete: SetNull) - @@unique([eventTypeId, field, targetLang]) // TODO: remove after migration @@unique([eventTypeId, field, targetLocale]) - @@index([eventTypeId, field, targetLang]) // TODO: remove after migration @@index([eventTypeId, field, targetLocale]) } From 4fca7f38647d52d9ad7a8cc17ce8b9c56f5ac5f4 Mon Sep 17 00:00:00 2001 From: hbjORbj Date: Wed, 4 Dec 2024 11:43:37 -0500 Subject: [PATCH 2/2] remove copying for sourceLocale and targetLocale --- .../migration.sql | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql b/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql index fd06846aa80e92..28efa8e7f05d2e 100644 --- a/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql +++ b/packages/prisma/migrations/20241127102756_remove_fields_from_evenet_type_translation/migration.sql @@ -9,11 +9,6 @@ */ --- Copy data -UPDATE "EventTypeTranslation" SET - "sourceLocale" = "sourceLang", - "targetLocale" = "targetLang"; - -- Copy data UPDATE "EventTypeTranslation" SET "uid" = "id";