@varaos/db 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "public"."ReactionType" AS ENUM ('LIKE', 'LOVE', 'CLAP', 'FIRE', 'WOW');
|
|
3
|
+
|
|
4
|
+
-- CreateTable
|
|
5
|
+
CREATE TABLE "public"."CommentIdentity" (
|
|
6
|
+
"id" TEXT NOT NULL,
|
|
7
|
+
"name" TEXT NOT NULL,
|
|
8
|
+
"email" TEXT NOT NULL,
|
|
9
|
+
"verified" BOOLEAN NOT NULL DEFAULT false,
|
|
10
|
+
"metadata" JSONB,
|
|
11
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
12
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
13
|
+
|
|
14
|
+
CONSTRAINT "CommentIdentity_pkey" PRIMARY KEY ("id")
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- CreateTable
|
|
18
|
+
CREATE TABLE "public"."PostComment" (
|
|
19
|
+
"id" TEXT NOT NULL,
|
|
20
|
+
"postId" TEXT NOT NULL,
|
|
21
|
+
"identityId" TEXT,
|
|
22
|
+
"parentId" TEXT,
|
|
23
|
+
"content" TEXT NOT NULL,
|
|
24
|
+
"status" "public"."Status" NOT NULL DEFAULT 'active',
|
|
25
|
+
"deletedAt" TIMESTAMP(3),
|
|
26
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
27
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
28
|
+
|
|
29
|
+
CONSTRAINT "PostComment_pkey" PRIMARY KEY ("id")
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
-- CreateTable
|
|
33
|
+
CREATE TABLE "public"."PostReaction" (
|
|
34
|
+
"id" TEXT NOT NULL,
|
|
35
|
+
"postId" TEXT NOT NULL,
|
|
36
|
+
"userId" TEXT,
|
|
37
|
+
"identityId" TEXT,
|
|
38
|
+
"type" "public"."ReactionType" NOT NULL,
|
|
39
|
+
"status" "public"."Status" NOT NULL DEFAULT 'active',
|
|
40
|
+
"deletedAt" TIMESTAMP(3),
|
|
41
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
42
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
43
|
+
|
|
44
|
+
CONSTRAINT "PostReaction_pkey" PRIMARY KEY ("id")
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
-- CreateTable
|
|
48
|
+
CREATE TABLE "public"."PostShare" (
|
|
49
|
+
"id" TEXT NOT NULL,
|
|
50
|
+
"postId" TEXT NOT NULL,
|
|
51
|
+
"userId" TEXT,
|
|
52
|
+
"identityId" TEXT,
|
|
53
|
+
"platform" TEXT,
|
|
54
|
+
"metadata" JSONB,
|
|
55
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
56
|
+
|
|
57
|
+
CONSTRAINT "PostShare_pkey" PRIMARY KEY ("id")
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
-- CreateIndex
|
|
61
|
+
CREATE UNIQUE INDEX "CommentIdentity_email_key" ON "public"."CommentIdentity"("email");
|
|
62
|
+
|
|
63
|
+
-- CreateIndex
|
|
64
|
+
CREATE INDEX "CommentIdentity_email_idx" ON "public"."CommentIdentity"("email");
|
|
65
|
+
|
|
66
|
+
-- CreateIndex
|
|
67
|
+
CREATE INDEX "PostComment_postId_idx" ON "public"."PostComment"("postId");
|
|
68
|
+
|
|
69
|
+
-- CreateIndex
|
|
70
|
+
CREATE INDEX "PostComment_identityId_idx" ON "public"."PostComment"("identityId");
|
|
71
|
+
|
|
72
|
+
-- CreateIndex
|
|
73
|
+
CREATE INDEX "PostComment_parentId_idx" ON "public"."PostComment"("parentId");
|
|
74
|
+
|
|
75
|
+
-- CreateIndex
|
|
76
|
+
CREATE INDEX "PostComment_status_idx" ON "public"."PostComment"("status");
|
|
77
|
+
|
|
78
|
+
-- CreateIndex
|
|
79
|
+
CREATE INDEX "PostReaction_postId_idx" ON "public"."PostReaction"("postId");
|
|
80
|
+
|
|
81
|
+
-- CreateIndex
|
|
82
|
+
CREATE INDEX "PostReaction_userId_idx" ON "public"."PostReaction"("userId");
|
|
83
|
+
|
|
84
|
+
-- CreateIndex
|
|
85
|
+
CREATE INDEX "PostReaction_identityId_idx" ON "public"."PostReaction"("identityId");
|
|
86
|
+
|
|
87
|
+
-- CreateIndex
|
|
88
|
+
CREATE INDEX "PostReaction_type_idx" ON "public"."PostReaction"("type");
|
|
89
|
+
|
|
90
|
+
-- CreateIndex
|
|
91
|
+
CREATE UNIQUE INDEX "PostReaction_postId_userId_type_key" ON "public"."PostReaction"("postId", "userId", "type");
|
|
92
|
+
|
|
93
|
+
-- CreateIndex
|
|
94
|
+
CREATE UNIQUE INDEX "PostReaction_postId_identityId_type_key" ON "public"."PostReaction"("postId", "identityId", "type");
|
|
95
|
+
|
|
96
|
+
-- CreateIndex
|
|
97
|
+
CREATE INDEX "PostShare_postId_idx" ON "public"."PostShare"("postId");
|
|
98
|
+
|
|
99
|
+
-- CreateIndex
|
|
100
|
+
CREATE INDEX "PostShare_userId_idx" ON "public"."PostShare"("userId");
|
|
101
|
+
|
|
102
|
+
-- CreateIndex
|
|
103
|
+
CREATE INDEX "PostShare_identityId_idx" ON "public"."PostShare"("identityId");
|
|
104
|
+
|
|
105
|
+
-- CreateIndex
|
|
106
|
+
CREATE INDEX "PostShare_platform_idx" ON "public"."PostShare"("platform");
|
|
107
|
+
|
|
108
|
+
-- AddForeignKey
|
|
109
|
+
ALTER TABLE "public"."PostComment" ADD CONSTRAINT "PostComment_postId_fkey" FOREIGN KEY ("postId") REFERENCES "public"."Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
110
|
+
|
|
111
|
+
-- AddForeignKey
|
|
112
|
+
ALTER TABLE "public"."PostComment" ADD CONSTRAINT "PostComment_identityId_fkey" FOREIGN KEY ("identityId") REFERENCES "public"."CommentIdentity"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
113
|
+
|
|
114
|
+
-- AddForeignKey
|
|
115
|
+
ALTER TABLE "public"."PostComment" ADD CONSTRAINT "PostComment_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "public"."PostComment"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
116
|
+
|
|
117
|
+
-- AddForeignKey
|
|
118
|
+
ALTER TABLE "public"."PostReaction" ADD CONSTRAINT "PostReaction_postId_fkey" FOREIGN KEY ("postId") REFERENCES "public"."Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
119
|
+
|
|
120
|
+
-- AddForeignKey
|
|
121
|
+
ALTER TABLE "public"."PostReaction" ADD CONSTRAINT "PostReaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
122
|
+
|
|
123
|
+
-- AddForeignKey
|
|
124
|
+
ALTER TABLE "public"."PostReaction" ADD CONSTRAINT "PostReaction_identityId_fkey" FOREIGN KEY ("identityId") REFERENCES "public"."CommentIdentity"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
125
|
+
|
|
126
|
+
-- AddForeignKey
|
|
127
|
+
ALTER TABLE "public"."PostShare" ADD CONSTRAINT "PostShare_postId_fkey" FOREIGN KEY ("postId") REFERENCES "public"."Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
128
|
+
|
|
129
|
+
-- AddForeignKey
|
|
130
|
+
ALTER TABLE "public"."PostShare" ADD CONSTRAINT "PostShare_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
131
|
+
|
|
132
|
+
-- AddForeignKey
|
|
133
|
+
ALTER TABLE "public"."PostShare" ADD CONSTRAINT "PostShare_identityId_fkey" FOREIGN KEY ("identityId") REFERENCES "public"."CommentIdentity"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Warnings:
|
|
3
|
+
|
|
4
|
+
- You are about to drop the column `userId` on the `PostReaction` table. All the data in the column will be lost.
|
|
5
|
+
- You are about to drop the column `userId` on the `PostShare` table. All the data in the column will be lost.
|
|
6
|
+
- A unique constraint covering the columns `[postId,visitorId,type]` on the table `PostReaction` will be added. If there are existing duplicate values, this will fail.
|
|
7
|
+
|
|
8
|
+
*/
|
|
9
|
+
-- DropForeignKey
|
|
10
|
+
ALTER TABLE "public"."PostReaction" DROP CONSTRAINT "PostReaction_userId_fkey";
|
|
11
|
+
|
|
12
|
+
-- DropForeignKey
|
|
13
|
+
ALTER TABLE "public"."PostShare" DROP CONSTRAINT "PostShare_userId_fkey";
|
|
14
|
+
|
|
15
|
+
-- DropIndex
|
|
16
|
+
DROP INDEX "public"."PostReaction_postId_userId_type_key";
|
|
17
|
+
|
|
18
|
+
-- DropIndex
|
|
19
|
+
DROP INDEX "public"."PostReaction_userId_idx";
|
|
20
|
+
|
|
21
|
+
-- DropIndex
|
|
22
|
+
DROP INDEX "public"."PostShare_userId_idx";
|
|
23
|
+
|
|
24
|
+
-- AlterTable
|
|
25
|
+
ALTER TABLE "public"."PostReaction" DROP COLUMN "userId",
|
|
26
|
+
ADD COLUMN "visitorId" TEXT;
|
|
27
|
+
|
|
28
|
+
-- AlterTable
|
|
29
|
+
ALTER TABLE "public"."PostShare" DROP COLUMN "userId",
|
|
30
|
+
ADD COLUMN "visitorId" TEXT;
|
|
31
|
+
|
|
32
|
+
-- CreateIndex
|
|
33
|
+
CREATE INDEX "PostReaction_visitorId_idx" ON "public"."PostReaction"("visitorId");
|
|
34
|
+
|
|
35
|
+
-- CreateIndex
|
|
36
|
+
CREATE UNIQUE INDEX "PostReaction_postId_visitorId_type_key" ON "public"."PostReaction"("postId", "visitorId", "type");
|
|
37
|
+
|
|
38
|
+
-- CreateIndex
|
|
39
|
+
CREATE INDEX "PostShare_visitorId_idx" ON "public"."PostShare"("visitorId");
|
|
40
|
+
|
|
41
|
+
-- AddForeignKey
|
|
42
|
+
ALTER TABLE "public"."PostReaction" ADD CONSTRAINT "PostReaction_visitorId_fkey" FOREIGN KEY ("visitorId") REFERENCES "public"."Visitor"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
43
|
+
|
|
44
|
+
-- AddForeignKey
|
|
45
|
+
ALTER TABLE "public"."PostShare" ADD CONSTRAINT "PostShare_visitorId_fkey" FOREIGN KEY ("visitorId") REFERENCES "public"."Visitor"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
package/prisma/schema.prisma
CHANGED
|
@@ -52,6 +52,14 @@ enum PostType {
|
|
|
52
52
|
SESSION
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
enum ReactionType {
|
|
56
|
+
LIKE
|
|
57
|
+
LOVE
|
|
58
|
+
CLAP
|
|
59
|
+
FIRE
|
|
60
|
+
WOW
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
/// ─────────────────────────────────────────────
|
|
56
64
|
/// USERS & AUTH
|
|
57
65
|
/// ─────────────────────────────────────────────
|
|
@@ -588,8 +596,10 @@ model Visitor {
|
|
|
588
596
|
lastVisit DateTime @updatedAt
|
|
589
597
|
visitCount Int @default(1)
|
|
590
598
|
|
|
591
|
-
createdAt
|
|
592
|
-
updatedAt
|
|
599
|
+
createdAt DateTime @default(now())
|
|
600
|
+
updatedAt DateTime @updatedAt
|
|
601
|
+
postReactions PostReaction[]
|
|
602
|
+
postShares PostShare[]
|
|
593
603
|
|
|
594
604
|
@@index([createdAt])
|
|
595
605
|
}
|
|
@@ -628,27 +638,30 @@ model EmailSendLog {
|
|
|
628
638
|
}
|
|
629
639
|
|
|
630
640
|
model Post {
|
|
631
|
-
id
|
|
632
|
-
title
|
|
633
|
-
slug
|
|
634
|
-
excerpt
|
|
635
|
-
type
|
|
636
|
-
status
|
|
641
|
+
id String @id @default(uuid())
|
|
642
|
+
title String
|
|
643
|
+
slug String @unique
|
|
644
|
+
excerpt String?
|
|
645
|
+
type PostType @default(BLOG)
|
|
646
|
+
status Status @default(draft)
|
|
637
647
|
|
|
638
|
-
content
|
|
639
|
-
contentHtml
|
|
648
|
+
content Json
|
|
649
|
+
contentHtml String?
|
|
640
650
|
|
|
641
651
|
featuredImage String?
|
|
642
652
|
|
|
643
653
|
// many-to-many pivot
|
|
644
|
-
tags
|
|
654
|
+
tags PostTag[] @relation("PostTags")
|
|
645
655
|
|
|
646
|
-
authorId
|
|
647
|
-
author
|
|
656
|
+
authorId String?
|
|
657
|
+
author User? @relation(fields: [authorId], references: [id])
|
|
648
658
|
|
|
649
659
|
publishedAt DateTime?
|
|
650
|
-
createdAt DateTime
|
|
651
|
-
updatedAt DateTime
|
|
660
|
+
createdAt DateTime @default(now())
|
|
661
|
+
updatedAt DateTime @updatedAt
|
|
662
|
+
postComments PostComment[]
|
|
663
|
+
postReactions PostReaction[]
|
|
664
|
+
postShares PostShare[]
|
|
652
665
|
|
|
653
666
|
@@index([type])
|
|
654
667
|
@@index([status])
|
|
@@ -656,9 +669,9 @@ model Post {
|
|
|
656
669
|
}
|
|
657
670
|
|
|
658
671
|
model Tag {
|
|
659
|
-
id String
|
|
660
|
-
name String
|
|
661
|
-
color String
|
|
672
|
+
id String @id @default(uuid())
|
|
673
|
+
name String @unique
|
|
674
|
+
color String @default("blue")
|
|
662
675
|
// inverse many-to-many pivot
|
|
663
676
|
posts PostTag[] @relation("PostTags")
|
|
664
677
|
}
|
|
@@ -673,4 +686,107 @@ model PostTag {
|
|
|
673
686
|
|
|
674
687
|
@@id([postId, tagId])
|
|
675
688
|
@@index([tagId])
|
|
676
|
-
}
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/// ─────────────────────────────────────────────
|
|
692
|
+
/// COMMENT IDENTITIES (Name + Email Login-less System)
|
|
693
|
+
/// ─────────────────────────────────────────────
|
|
694
|
+
|
|
695
|
+
model CommentIdentity {
|
|
696
|
+
id String @id @default(uuid())
|
|
697
|
+
name String
|
|
698
|
+
email String @unique
|
|
699
|
+
verified Boolean @default(false)
|
|
700
|
+
metadata Json?
|
|
701
|
+
|
|
702
|
+
createdAt DateTime @default(now())
|
|
703
|
+
updatedAt DateTime @updatedAt
|
|
704
|
+
|
|
705
|
+
comments PostComment[]
|
|
706
|
+
postReactions PostReaction[]
|
|
707
|
+
postShares PostShare[]
|
|
708
|
+
|
|
709
|
+
@@index([email])
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
/// ─────────────────────────────────────────────
|
|
713
|
+
/// POST COMMENTS (Revised to use CommentIdentity)
|
|
714
|
+
/// ─────────────────────────────────────────────
|
|
715
|
+
|
|
716
|
+
model PostComment {
|
|
717
|
+
id String @id @default(uuid())
|
|
718
|
+
postId String
|
|
719
|
+
identityId String? // Instead of userId (for public commenters)
|
|
720
|
+
parentId String? // Threaded comments
|
|
721
|
+
|
|
722
|
+
content String
|
|
723
|
+
status Status @default(active)
|
|
724
|
+
deletedAt DateTime?
|
|
725
|
+
|
|
726
|
+
// Relations
|
|
727
|
+
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
|
|
728
|
+
identity CommentIdentity? @relation(fields: [identityId], references: [id])
|
|
729
|
+
parent PostComment? @relation("CommentReplies", fields: [parentId], references: [id])
|
|
730
|
+
replies PostComment[] @relation("CommentReplies")
|
|
731
|
+
|
|
732
|
+
createdAt DateTime @default(now())
|
|
733
|
+
updatedAt DateTime @updatedAt
|
|
734
|
+
|
|
735
|
+
@@index([postId])
|
|
736
|
+
@@index([identityId])
|
|
737
|
+
@@index([parentId])
|
|
738
|
+
@@index([status])
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/// ─────────────────────────────────────────────
|
|
742
|
+
/// POST REACTIONS (LIKE, LOVE, CLAP, FIRE, WOW)
|
|
743
|
+
/// ─────────────────────────────────────────────
|
|
744
|
+
|
|
745
|
+
model PostReaction {
|
|
746
|
+
id String @id @default(uuid())
|
|
747
|
+
postId String
|
|
748
|
+
visitorId String? // Could be Visitor.visitorId
|
|
749
|
+
identityId String? // If commenter also reacts
|
|
750
|
+
type ReactionType
|
|
751
|
+
|
|
752
|
+
status Status @default(active)
|
|
753
|
+
deletedAt DateTime?
|
|
754
|
+
|
|
755
|
+
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
|
|
756
|
+
visitor Visitor? @relation(fields: [visitorId], references: [id])
|
|
757
|
+
identity CommentIdentity? @relation(fields: [identityId], references: [id])
|
|
758
|
+
|
|
759
|
+
createdAt DateTime @default(now())
|
|
760
|
+
updatedAt DateTime @updatedAt
|
|
761
|
+
|
|
762
|
+
@@unique([postId, visitorId, type])
|
|
763
|
+
@@unique([postId, identityId, type])
|
|
764
|
+
@@index([postId])
|
|
765
|
+
@@index([visitorId])
|
|
766
|
+
@@index([identityId])
|
|
767
|
+
@@index([type])
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/// ─────────────────────────────────────────────
|
|
771
|
+
/// POST SHARES (Analytics + Share Platform Info)
|
|
772
|
+
/// ─────────────────────────────────────────────
|
|
773
|
+
|
|
774
|
+
model PostShare {
|
|
775
|
+
id String @id @default(uuid())
|
|
776
|
+
postId String
|
|
777
|
+
visitorId String?
|
|
778
|
+
identityId String?
|
|
779
|
+
platform String? // twitter | whatsapp | copy | linkedin | etc.
|
|
780
|
+
metadata Json?
|
|
781
|
+
|
|
782
|
+
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
|
|
783
|
+
visitor Visitor? @relation(fields: [visitorId], references: [id])
|
|
784
|
+
identity CommentIdentity? @relation(fields: [identityId], references: [id])
|
|
785
|
+
|
|
786
|
+
createdAt DateTime @default(now())
|
|
787
|
+
|
|
788
|
+
@@index([postId])
|
|
789
|
+
@@index([visitorId])
|
|
790
|
+
@@index([identityId])
|
|
791
|
+
@@index([platform])
|
|
792
|
+
}
|