From 99ce6c6e45fa98f72689225cc7e3ca7f1f4ba39f Mon Sep 17 00:00:00 2001 From: Satoshi Nakamoto Date: Thu, 12 Oct 2023 12:15:11 -0400 Subject: [PATCH] Add a discussion post with a lot of comments to help debug in dev to the seed file --- prisma/seed.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/prisma/seed.js b/prisma/seed.js index 2f102eaa..6202eb61 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -1,5 +1,27 @@ const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() + +function selectRandomly (items) { + return items[Math.floor(Math.random() * items.length)] +} + +async function addComments (parentIds, nComments, userIds, commentText) { + const clonedParentIds = [...parentIds] + const clonedUserIds = [...userIds] + for (let i = 0; i < nComments; i++) { + const selectedParent = selectRandomly(clonedParentIds) + const selectedUserId = selectRandomly(clonedUserIds) + const newComment = await prisma.item.create({ + data: { + parentId: selectedParent, + userId: selectedUserId, + text: commentText + } + }) + clonedParentIds.push(newComment.id) + } +} + async function main () { const k00b = await prisma.user.upsert({ where: { name: 'k00b' }, @@ -155,6 +177,17 @@ async function main () { } } }) + + const bigCommentPost = await prisma.item.create({ + data: { + title: 'a discussion post with a lot of comments', + text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', + userId: k00b.id, + subName: 'bitcoin' + } + }) + + addComments([bigCommentPost.id], 200, [k00b.id, anon.id, satoshi.id, greg.id, stan.id], 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.') } main() .catch(e => {