add recipient field to messages and phone calls

This commit is contained in:
m5r
2022-05-22 01:17:43 +02:00
parent 6684dcc0e5
commit 1f37eb45d5
6 changed files with 78 additions and 58 deletions

View File

@ -118,6 +118,7 @@ CREATE TABLE "Message" (
"id" TEXT NOT NULL,
"sentAt" TIMESTAMPTZ NOT NULL,
"content" TEXT NOT NULL,
"recipient" TEXT NOT NULL,
"from" TEXT NOT NULL,
"to" TEXT NOT NULL,
"direction" "Direction" NOT NULL,
@ -131,6 +132,7 @@ CREATE TABLE "Message" (
CREATE TABLE "PhoneCall" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"recipient" TEXT NOT NULL,
"from" TEXT NOT NULL,
"to" TEXT NOT NULL,
"status" "CallStatus" NOT NULL,
@ -172,11 +174,17 @@ CREATE UNIQUE INDEX "Token_membershipId_key" ON "Token"("membershipId");
-- CreateIndex
CREATE UNIQUE INDEX "Token_hashedToken_type_key" ON "Token"("hashedToken", "type");
-- CreateIndex
CREATE INDEX "Message_phoneNumberId_recipient_idx" ON "Message"("phoneNumberId", "recipient");
-- CreateIndex
CREATE INDEX "PhoneCall_phoneNumberId_recipient_idx" ON "PhoneCall"("phoneNumberId", "recipient");
-- CreateIndex
CREATE UNIQUE INDEX "PhoneNumber_organizationId_isCurrent_key" ON "PhoneNumber"("organizationId", "isCurrent") WHERE ("isCurrent" = true);
-- AddForeignKey
ALTER TABLE "TwilioAccount" ADD CONSTRAINT "TwilioAccount_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE "TwilioAccount" ADD CONSTRAINT "TwilioAccount_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey

View File

@ -17,7 +17,7 @@ model TwilioAccount {
twimlAppSid String?
organizationId String @unique
organization Organization @relation(fields: [organizationId], references: [id])
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
}
model Organization {
@ -105,17 +105,21 @@ model Message {
id String @id
sentAt DateTime @db.Timestamptz(6)
content String
recipient String
from String
to String
direction Direction
status MessageStatus
phoneNumberId String
phoneNumber PhoneNumber @relation(fields: [phoneNumberId], references: [id], onDelete: Cascade)
@@index([phoneNumberId, recipient])
}
model PhoneCall {
id String @id
createdAt DateTime @default(now()) @db.Timestamptz(6)
recipient String
from String
to String
status CallStatus
@ -123,6 +127,8 @@ model PhoneCall {
duration String
phoneNumberId String
phoneNumber PhoneNumber @relation(fields: [phoneNumberId], references: [id], onDelete: Cascade)
@@index([phoneNumberId, recipient])
}
model PhoneNumber {