Skip to content

Commit

Permalink
Migration query + Schedule->EventType to EventType->Schedule (calcom#…
Browse files Browse the repository at this point in the history
…3140)

* Wrote migration query + change Schedule->EventType to EventType->Schedule

* Removed warning as it is not strictly true
  • Loading branch information
emrysal authored Jun 22, 2022
1 parent 40a1824 commit 6f354e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

-- DropForeignKey
ALTER TABLE "Schedule" DROP CONSTRAINT "Schedule_eventTypeId_fkey";

-- DropIndex
DROP INDEX "Schedule_eventTypeId_key";

-- AlterTable
ALTER TABLE "EventType" ADD COLUMN "scheduleId" INTEGER;

UPDATE "EventType"
SET
"scheduleId" = subquery.id
FROM (
SELECT id, "eventTypeId" FROM "Schedule"
) AS subquery
WHERE
"EventType".id = subquery."eventTypeId";

-- AlterTable
ALTER TABLE "Schedule" DROP COLUMN "eventTypeId";

-- AddForeignKey
ALTER TABLE "EventType" ADD CONSTRAINT "EventType_scheduleId_fkey" FOREIGN KEY ("scheduleId") REFERENCES "Schedule"("id") ON DELETE SET NULL ON UPDATE CASCADE;
6 changes: 3 additions & 3 deletions packages/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ model EventType {
afterEventBuffer Int @default(0)
seatsPerTimeSlot Int?
schedulingType SchedulingType?
schedule Schedule?
schedule Schedule? @relation(fields: [scheduleId], references: [id])
scheduleId Int?
price Int @default(0)
currency String @default("usd")
slotInterval Int?
Expand Down Expand Up @@ -292,8 +293,7 @@ model Schedule {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
eventType EventType? @relation(fields: [eventTypeId], references: [id])
eventTypeId Int? @unique
eventType EventType[]
name String
timeZone String?
availability Availability[]
Expand Down

0 comments on commit 6f354e0

Please sign in to comment.