Skip to content

Commit 3cf402e

Browse files
committed
custom domains - brandings
- SubBranding schema and typedefs
1 parent 6a0b2cc commit 3cf402e

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

api/typeDefs/sub.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default gql`
88
topSubs(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Subs
99
userSubs(name: String!, cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Subs
1010
subSuggestions(q: String!, limit: Limit): [Sub!]!
11+
subBranding(subName: String!): SubBranding
1112
}
1213
1314
type Subs {
@@ -29,6 +30,7 @@ export default gql`
2930
replyCost: Int!, postTypes: [String!]!,
3031
billingType: String!, billingAutoRenew: Boolean!,
3132
moderated: Boolean!, nsfw: Boolean!): SubPaidAction!
33+
setSubBranding(subName: String!, branding: SubBrandingInput): SubBranding!
3234
}
3335
3436
type Sub {
@@ -68,4 +70,24 @@ export default gql`
6870
spent(when: String, from: String, to: String): Int
6971
revenue(when: String, from: String, to: String): Int
7072
}
73+
74+
type SubBranding {
75+
id: Int!
76+
subName: String!
77+
title: String
78+
description: String
79+
logoId: Int
80+
faviconId: Int
81+
primaryColor: String
82+
secondaryColor: String
83+
}
84+
85+
input SubBrandingInput {
86+
title: String
87+
description: String
88+
logoId: Int
89+
faviconId: Int
90+
primaryColor: String
91+
secondaryColor: String
92+
}
7193
`
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- CreateTable
2+
CREATE TABLE "SubBranding" (
3+
"id" SERIAL NOT NULL,
4+
"subName" CITEXT NOT NULL,
5+
"title" TEXT,
6+
"description" TEXT,
7+
"logoId" INTEGER,
8+
"faviconId" INTEGER,
9+
"primaryColor" TEXT,
10+
"secondaryColor" TEXT,
11+
12+
CONSTRAINT "SubBranding_pkey" PRIMARY KEY ("id")
13+
);
14+
15+
-- CreateIndex
16+
CREATE UNIQUE INDEX "SubBranding_subName_key" ON "SubBranding"("subName");
17+
18+
-- CreateIndex
19+
CREATE INDEX "SubBranding_subName_idx" ON "SubBranding"("subName");
20+
21+
-- AddForeignKey
22+
ALTER TABLE "SubBranding" ADD CONSTRAINT "SubBranding_logoId_fkey" FOREIGN KEY ("logoId") REFERENCES "Upload"("id") ON DELETE SET NULL ON UPDATE CASCADE;
23+
24+
-- AddForeignKey
25+
ALTER TABLE "SubBranding" ADD CONSTRAINT "SubBranding_faviconId_fkey" FOREIGN KEY ("faviconId") REFERENCES "Upload"("id") ON DELETE SET NULL ON UPDATE CASCADE;
26+
27+
-- AddForeignKey
28+
ALTER TABLE "SubBranding" ADD CONSTRAINT "SubBranding_subName_fkey" FOREIGN KEY ("subName") REFERENCES "Sub"("name") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ model Upload {
455455
user User @relation("Uploads", fields: [userId], references: [id], onDelete: Cascade)
456456
User User[]
457457
ItemUpload ItemUpload[]
458+
SubBrandingLogo SubBranding[] @relation("SubBrandingLogo")
459+
SubBrandingFavicon SubBranding[] @relation("SubBrandingFavicon")
458460
459461
@@index([createdAt], map: "Upload.created_at_index")
460462
@@index([userId], map: "Upload.userId_index")
@@ -802,6 +804,7 @@ model Sub {
802804
TerritoryTransfer TerritoryTransfer[]
803805
UserSubTrust UserSubTrust[]
804806
domain Domain?
807+
branding SubBranding?
805808
806809
@@index([parentName])
807810
@@index([createdAt])
@@ -1262,6 +1265,23 @@ model Domain {
12621265
@@index([subName])
12631266
}
12641267

1268+
model SubBranding {
1269+
id Int @id @default(autoincrement())
1270+
subName String @unique @db.Citext
1271+
title String? // default title of the sub
1272+
description String? // default description of the sub
1273+
logoId Int?
1274+
faviconId Int?
1275+
primaryColor String?
1276+
secondaryColor String?
1277+
1278+
logoUpload Upload? @relation("SubBrandingLogo", fields: [logoId], references: [id], onDelete: SetNull)
1279+
faviconUpload Upload? @relation("SubBrandingFavicon", fields: [faviconId], references: [id], onDelete: SetNull)
1280+
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade, onUpdate: Cascade)
1281+
1282+
@@index([subName])
1283+
}
1284+
12651285
model DomainVerificationAttempt {
12661286
id Int @id @default(autoincrement())
12671287
createdAt DateTime @default(now()) @map("created_at")

0 commit comments

Comments
 (0)