chore: drop sourceLang, targetLang and id columns (#17792)

* chore: drop sourceLang, targetLang and id columns

* remove copying for sourceLocale and targetLocale
This commit is contained in:
Benny Joo authored and GitHub committed 2024-12-05 17:23:07 +01:00
1 parent c96827e1c0
commit 2a578ea9d5
4 files changed
+36 -26

No files matched your search

@@ -63,9 +63,6 @@ export async function translateEventTypeDescription(payload: string): Promise<vo
eventTypeId,
sourceLocale: userLocale,
targetLocale,
// Keep old fields during transition
sourceLang: userLocale, // TODO: remove after migration
targetLang: targetLocale, // TODO: remove after migration
translatedText,
userId,
}))
@@ -4,7 +4,6 @@ import { EventTypeAutoTranslatedField } from "@calcom/prisma/enums";
export type CreateEventTypeDescriptionTranslation = Omit<
EventTypeTranslation,
| "id" // TODO: remove after migration
| "uid"
| "createdAt"
| "createdBy"
@@ -20,23 +19,14 @@ export class EventTypeTranslationRepository {
static async upsertManyDescriptionTranslations(translations: Array<CreateEventTypeDescriptionTranslation>) {
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,
@@ -0,0 +1,28 @@
/*
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
"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");
+1 -6
View File
@@ -1639,13 +1639,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
@@ -1656,9 +1653,7 @@ 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])
}