Skip to content

Commit c1a6c2f

Browse files
committed
feat: support social links in db.
1 parent 91390b2 commit c1a6c2f

File tree

12 files changed

+149
-35
lines changed

12 files changed

+149
-35
lines changed

package-lock.json

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@mui/material-nextjs": "^6.1.8",
4646
"@next-auth/prisma-adapter": "^1.0.7",
4747
"@next/third-parties": "^15.0.3",
48-
"@prisma/client": "^6.0.1",
48+
"@prisma/client": "^6.2.1",
4949
"@sentry/nextjs": "^8.48.0",
5050
"@tanstack/react-query": "^5.62.7",
5151
"classnames": "^2.5.1",
@@ -80,7 +80,7 @@
8080
"jest": "^29.7.0",
8181
"jest-environment-jsdom": "^29.7.0",
8282
"prettier": "^3.3.3",
83-
"prisma": "^6.0.1",
83+
"prisma": "^6.2.1",
8484
"ts-jest": "^29.2.5",
8585
"ts-node": "^10.9.2",
8686
"tsx": "^4.19.2",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- CreateTable
2+
CREATE TABLE "Social" (
3+
"id" TEXT NOT NULL,
4+
"name" TEXT NOT NULL,
5+
"urlSuffix" TEXT NOT NULL,
6+
"userId" TEXT NOT NULL,
7+
8+
CONSTRAINT "Social_pkey" PRIMARY KEY ("id")
9+
);
10+
11+
-- AddForeignKey
12+
ALTER TABLE "Social" ADD CONSTRAINT "Social_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `urlSuffix` on the `Social` table. All the data in the column will be lost.
5+
- Added the required column `url` to the `Social` table without a default value. This is not possible if the table is not empty.
6+
7+
*/
8+
-- AlterTable
9+
ALTER TABLE "Social" DROP COLUMN "urlSuffix",
10+
ADD COLUMN "url" TEXT NOT NULL;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
2+
# It should be added in your version-control system (e.g., Git)
33
provider = "postgresql"

prisma/schema.prisma

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ model User {
5959
skillForUser SkillForUser[] // One-to-many relationship with SkillForUser, customized skills per user.
6060
company Company[] // One-to-many relationship with Company, work experience. Can be multiple companies.
6161
education Education[] // One-to-many relationship with Education, education history. Can be multiple schools.
62+
Social Social[] // One-to-many relationship with Social, social media links or usernames.
6263
}
6364

6465
model VerificationToken {
@@ -69,6 +70,19 @@ model VerificationToken {
6970
@@unique([identifier, token])
7071
}
7172

73+
// Social media links for a user, e.g. "Twitter", "GitHub", "LinkedIn"
74+
model Social {
75+
id String @id @default(cuid())
76+
name String
77+
// URL base dpends on the name, e.g. "https://{name}.com/{username}"
78+
// So, if name is "twitter", and username is "jack", the full URL will be "https://twitter.com/jack"
79+
// Or if it's LinkedIn, it will be "https://linkedin.com/in/{username}"
80+
// However, if the name is "website" or "personal", then the URL should be the full URL.
81+
url String
82+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
83+
userId String
84+
}
85+
7286
// Skill is a general skill that can be used by multiple users, e.g. "HTML", "CSS", "JavaScript"
7387
// Not limited to technical skills. Can be used for any skill, e.g. "Public Speaking", "Leadership"
7488
model Skill {

prisma/seed/all.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import { seedProjects } from "./project";
55
import { seedSkills } from "./skills";
66
import { seedSkillsForProject } from "./skillsForProject";
77
import { seedSkillsForUser } from "./skillsForUser";
8+
import { seedSocials } from "./social";
89
import { seedUsers } from "./users";
910

1011
async function seed() {
1112
await seedUsers();
13+
await seedSocials();
1214
await seedCompanies();
1315
await seedPositions();
1416
await seedProjects();

prisma/seed/social.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* eslint-disable no-console */
2+
3+
import { fileURLToPath } from "url";
4+
import { getTestUserIds } from "./helpers/ids";
5+
import { logTitle } from "./helpers/util";
6+
import { prisma } from "@/lib/prisma";
7+
8+
export async function seedSocials() {
9+
logTitle("Seeding Demo Social Media Links");
10+
11+
const testUserIds = await getTestUserIds();
12+
13+
const socials = [
14+
{
15+
name: "GitHub",
16+
url: "missionmike",
17+
},
18+
{
19+
name: "LinkedIn",
20+
url: "michael-dinerstein",
21+
},
22+
{
23+
name: "X",
24+
url: "missionmikedev",
25+
},
26+
{
27+
name: "Website",
28+
url: "https://www.missionmike.dev",
29+
},
30+
];
31+
32+
for (const userId of testUserIds) {
33+
console.log(`Deleting existing socials for user ${userId}`);
34+
await prisma.social.deleteMany({
35+
where: {
36+
userId,
37+
},
38+
});
39+
40+
for (const social of socials) {
41+
const createdSocial = await prisma.social.create({
42+
data: {
43+
userId,
44+
...social,
45+
},
46+
});
47+
console.log(`Created social ${social.name} for user ${userId} with id: ${createdSocial.id}`);
48+
}
49+
}
50+
}
51+
52+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
53+
seedSocials()
54+
.catch((e) => {
55+
throw e;
56+
})
57+
.finally(async () => {
58+
await prisma.$disconnect();
59+
});
60+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { prisma } from "@/lib/prisma";
2+
3+
export const getSocials = async (_: string, { userId }: { userId: string }) =>
4+
await prisma.social.findMany({
5+
where: { userId },
6+
});

src/graphql/server/resolvers/queryDefs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const queryDefs = gql`
77
88
# User-specific queries.
99
user(slug: String!): User
10+
socials(userId: ID!): [Social!]!
1011
skillsForUser(userId: ID!): [SkillForUser!]!
1112
companies(userId: ID!, sort: [SortInput!]): [Company!]!
1213
positions(companyIds: [ID!], sort: [SortInput!]): [Position!]!

0 commit comments

Comments
 (0)