mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-02 10:41:54 +02:00
♻️ Refactor poll view tracking (#1644)
This commit is contained in:
parent
6b914610d9
commit
f05f437b56
13 changed files with 288 additions and 41 deletions
|
@ -0,0 +1,26 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "poll_views" (
|
||||
"id" TEXT NOT NULL,
|
||||
"poll_id" TEXT NOT NULL,
|
||||
"ip_address" TEXT,
|
||||
"user_id" TEXT,
|
||||
"user_agent" TEXT,
|
||||
"viewed_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "poll_views_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "poll_views_poll_id_idx" ON "poll_views" USING HASH ("poll_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "poll_views_user_id_idx" ON "poll_views" USING HASH ("user_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "poll_views_viewed_at_idx" ON "poll_views"("viewed_at");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "poll_views" ADD CONSTRAINT "poll_views_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "poll_views" ADD CONSTRAINT "poll_views_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@ -1,3 +1,3 @@
|
|||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "postgresql"
|
|
@ -62,6 +62,7 @@ model User {
|
|||
participants Participant[]
|
||||
paymentMethods PaymentMethod[]
|
||||
subscription Subscription? @relation("UserToSubscription")
|
||||
pollViews PollView[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
|
@ -167,6 +168,7 @@ model Poll {
|
|||
watchers Watcher[]
|
||||
comments Comment[]
|
||||
votes Vote[]
|
||||
views PollView[]
|
||||
|
||||
@@index([guestId])
|
||||
@@map("polls")
|
||||
|
@ -284,6 +286,23 @@ model Comment {
|
|||
@@map("comments")
|
||||
}
|
||||
|
||||
model PollView {
|
||||
id String @id @default(cuid())
|
||||
pollId String @map("poll_id")
|
||||
ipAddress String? @map("ip_address")
|
||||
userId String? @map("user_id")
|
||||
userAgent String? @map("user_agent")
|
||||
viewedAt DateTime @default(now()) @map("viewed_at")
|
||||
|
||||
poll Poll @relation(fields: [pollId], references: [id], onDelete: Cascade)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([pollId], type: Hash)
|
||||
@@index([userId], type: Hash)
|
||||
@@index([viewedAt])
|
||||
@@map("poll_views")
|
||||
}
|
||||
|
||||
model VerificationToken {
|
||||
identifier String @db.Citext
|
||||
token String @unique
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue