Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

prisma-fertilizer

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-fertilizer

Generate seed files for Prisma projects using Faker.js

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Prisma Fertilizer

Generate seed files for Prisma projects using Faker.js.

Overview

Prisma Fertilizer is a command-line tool that analyzes your Prisma schema and automatically generates a seed file with realistic fake data using Faker.js. This tool helps you quickly populate your database with test data that matches your schema's structure and relationships.

Features

  • Automatically analyzes your Prisma schema
  • Generates appropriate fake data based on field names and types
  • Respects relationships between models
  • Customizable number of records per model
  • Interactive model selection with checkbox interface
  • Smart default output path in the same directory as your schema file
  • Smart field detection for common field names (email, name, address, etc.)

Installation

Global Installation

npm install -g prisma-fertilizer

Local Installation

npm install --save-dev prisma-fertilizer

Usage

Command Line

# Basic usage with default options
npx prisma-fertilizer

# Specify schema path
npx prisma-fertilizer --schema ./path/to/schema.prisma

# Specify output path
npx prisma-fertilizer --output ./path/to/seed.js

# Generate 20 records per model
npx prisma-fertilizer --count 20

# Force overwrite of existing seed file
npx prisma-fertilizer --force

# Generate seed data for specific models only
npx prisma-fertilizer --models User,Post,Comment

Options

  • -s, --schema <path>: Path to your Prisma schema file (default: ./prisma/schema.prisma)
  • -o, --output <path>: Output path for the generated seed file (if not specified, defaults to the same directory as your schema file)
  • -c, --count <number>: Number of records to generate for each model (default: 10)
  • -f, --force: Overwrite existing seed file if it exists without prompting (default: false)
  • -y, --yes: Skip all confirmation prompts and use defaults (default: false)
  • -v, --version: Display version information
  • -h, --help: Display help information

Default Output Path

Prisma Fertilizer intelligently sets the default output path for your seed file to be in the same directory as your schema file. This means:

  • If your schema is at ./prisma/schema.prisma, the default output will be ./prisma/seed.js
  • If your schema is at ./src/database/schema.prisma, the default output will be ./src/database/seed.js

This behavior makes it easier to keep your seed files organized alongside your schema files, which is the recommended practice for Prisma projects.

Interactive Mode

When you run Prisma Fertilizer without using the -y flag, it will prompt you interactively:

$ prisma-fertilizer
🌱 Prisma Fertilizer - Generating seed file...
Where would you like to place the seed file? [./prisma/seed.js]: ./src/db/seed.js

# Model selection with checkboxes
Select models to generate seed data for (use space to select, enter to confirm):
❯◯ User
 ◯ Profile
 ◯ Post
 ◯ Comment
 ◯ Tag

The interactive mode provides a user-friendly checkbox interface for selecting which models to include in your seed file. Use the space bar to select/deselect models and press Enter to confirm your selection.

If the file already exists, it will ask for confirmation before overwriting:

File already exists at ./src/db/seed.js. Overwrite? (y/N):

Dependency Check

Prisma Fertilizer automatically checks if your project has the required @faker-js/faker dependency installed. If it's not found, it will offer to install it for you:

⚠️  Warning: @faker-js/faker is not installed in your project.
   The generated seed file will require this package to run.
Would you like to install @faker-js/faker as a dev dependency? (Y/n):

Example

For a schema with User and Post models:

model User {
  id        Int      @id @default(autoincrement())
  email     String   @unique
  name      String
  posts     Post[]
  createdAt DateTime @default(now())
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  Int
  createdAt DateTime @default(now())
}

The generated seed file will create users with realistic names and emails, and posts with appropriate titles and content, maintaining the relationships between them.

Contributors

See CONTRIBUTORS.md for a list of the project's contributors.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

prisma

FAQs

Package last updated on 23 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts