Posts

Showing posts with the label database seeding

Seeding bulk records with Snaplet Seed and PostgreSQL

Image
Introduction In the previous article, I provided a basic guide on how to use @snaplet/seed to seed data quickly. In this article, I will show you how to generate a large amount of data in a short time, approximately 1,000,000 records, which is useful when you need to perform performance testing. You can apply a similar approach to larger datasets like several million records, using a streaming mechanism to avoid Out of Memory (OOM) errors caused by allocating too much memory at once and overloading the system. I will explain two different approaches here: Coding: chunking data and writing each small part to the database Database: creating a CSV file and using a command to copy that data directly into PostgreSQL Prerequisites You need to set up Prisma, PostgreSQL and @snaplet/seed before continuing, you can check out the previous articles for instructions. Detail First, let us create the file prisma/seed/seed.ts import {faker} from '@faker-js/faker' import {createSeedClient}...