From 8dce5be08648f0aaffb5c6309f05016a06ecd3d2 Mon Sep 17 00:00:00 2001 From: Harshit Date: Mon, 15 Jun 2026 21:17:57 +0530 Subject: [PATCH] fix(seed): update prisma seed for latest schema --- apps/backend/prisma/seed.ts | 134 ++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/apps/backend/prisma/seed.ts b/apps/backend/prisma/seed.ts index f19345d8..8f3c6428 100644 --- a/apps/backend/prisma/seed.ts +++ b/apps/backend/prisma/seed.ts @@ -3,11 +3,12 @@ import { PrismaClient } from '@prisma/client'; const prisma = new PrismaClient(); async function main() { - console.log('🌱 Seeding DevCard database...'); + console.log('Seeding database.......'); - // Create test user - const testUser = await prisma.user.upsert({ - where: { username: 'devcard-demo' }, + const user = await prisma.user.upsert({ + where: { + username: 'devcard-demo', + }, update: {}, create: { email: 'demo@devcard.dev', @@ -17,83 +18,103 @@ async function main() { pronouns: 'they/them', role: 'Senior Software Engineer', company: 'OpenSource Inc.', - avatarUrl: null, accentColor: '#6366f1', - provider: 'github', - providerId: 'demo-12345', + isActive: true, + emailVerified: true, + + identities: { + create: { + provider: 'github', + providerId: 'demo-12345', + }, + }, }, }); - console.log(` āœ… Created user: ${testUser.displayName} (@${testUser.username})`); + console.log(`User created: ${user.username}`); + + await prisma.cardLink.deleteMany({}); + await prisma.card.deleteMany({}); + await prisma.platformLink.deleteMany({ + where: { + userId: user.id, + }, + }); - // Create platform links const links = await Promise.all([ prisma.platformLink.create({ data: { - userId: testUser.id, + userId: user.id, platform: 'github', username: 'alexchen', url: 'https://github.com/alexchen', displayOrder: 0, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, + userId: user.id, platform: 'linkedin', username: 'alexchen-dev', - url: 'https://www.linkedin.com/in/alexchen-dev', + url: 'https://linkedin.com/in/alexchen-dev', displayOrder: 1, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, + userId: user.id, platform: 'twitter', username: 'alexchendev', url: 'https://x.com/alexchendev', displayOrder: 2, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, - platform: 'devfolio', - username: 'alexchen', - url: 'https://devfolio.co/@alexchen', + userId: user.id, + platform: 'portfolio', + username: 'alexchen.dev', + url: 'https://alexchen.dev', displayOrder: 3, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, - platform: 'portfolio', - username: 'https://alexchen.dev', - url: 'https://alexchen.dev', + userId: user.id, + platform: 'devfolio', + username: 'alexchen', + url: 'https://devfolio.co/@alexchen', displayOrder: 4, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, + userId: user.id, platform: 'leetcode', username: 'alexchen', url: 'https://leetcode.com/u/alexchen', displayOrder: 5, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, + userId: user.id, platform: 'discord', username: 'alexchen#4242', url: '', displayOrder: 6, }, }), + prisma.platformLink.create({ data: { - userId: testUser.id, + userId: user.id, platform: 'email', username: 'alex@devcard.dev', url: 'mailto:alex@devcard.dev', @@ -102,20 +123,32 @@ async function main() { }), ]); - console.log(` āœ… Created ${links.length} platform links`); + console.log(`${links.length} platform links created`); - // Create context cards const professionalCard = await prisma.card.create({ data: { - userId: testUser.id, + userId: user.id, title: 'Professional', isDefault: true, + cardLinks: { create: [ - { platformLinkId: links[0].id, displayOrder: 0 }, // GitHub - { platformLinkId: links[1].id, displayOrder: 1 }, // LinkedIn - { platformLinkId: links[2].id, displayOrder: 2 }, // Twitter - { platformLinkId: links[4].id, displayOrder: 3 }, // Portfolio + { + platformLinkId: links[0].id, + displayOrder: 0, + }, + { + platformLinkId: links[1].id, + displayOrder: 1, + }, + { + platformLinkId: links[2].id, + displayOrder: 2, + }, + { + platformLinkId: links[3].id, + displayOrder: 3, + }, ], }, }, @@ -123,29 +156,44 @@ async function main() { const hackathonCard = await prisma.card.create({ data: { - userId: testUser.id, + userId: user.id, title: 'Hackathon', - isDefault: false, + cardLinks: { create: [ - { platformLinkId: links[0].id, displayOrder: 0 }, // GitHub - { platformLinkId: links[3].id, displayOrder: 1 }, // Devfolio - { platformLinkId: links[6].id, displayOrder: 2 }, // Discord - { platformLinkId: links[2].id, displayOrder: 3 }, // Twitter + { + platformLinkId: links[0].id, + displayOrder: 0, + }, + { + platformLinkId: links[4].id, + displayOrder: 1, + }, + { + platformLinkId: links[6].id, + displayOrder: 2, + }, + { + platformLinkId: links[2].id, + displayOrder: 3, + }, ], }, }, }); - console.log(` āœ… Created cards: "${professionalCard.title}", "${hackathonCard.title}"`); - console.log('\nšŸŽ‰ Seed complete! Try: GET /api/u/devcard-demo'); + console.log( + `Cards created: ${professionalCard.title}, ${hackathonCard.title}`, + ); + + console.log('\nSeed complete'); } main() - .catch((error) => { - console.error('āŒ Seed failed:', error); - process.exit(1); + .catch((err) => { + console.error('Seed failed', err); + return; }) .finally(async () => { await prisma.$disconnect(); - }); + }); \ No newline at end of file