Prisma is a modern database toolkit that serves as the ORM for Dirstarter. This guide explains how Prisma is configured and used in the project.
Prisma provides several key components:
- Prisma Client: Auto-generated type-safe query builder
- Prisma Schema: Defines your database models and relationships
- Prisma Migrate: Handles database migrations
- Prisma Studio: GUI to view and edit data
Dirstarter comes with Prisma pre-configured with PostgreSQL. The main Prisma-related files are:
prisma/schema.prisma
: Defines your database schemaprisma/seed.ts
: Contains seed data for developmentservices/db.ts
: Configures and exports the Prisma client
Setup
- Set up your PostgreSQL database
- Add your database URL to
.env
:.env
Database Management Commands
The following commands are available in package.json
:
Updating Database Schema
To update your database schema, edit the prisma/schema.prisma
file. Here's how to manage schema changes:
Create Migration (Optional)
To track schema changes in version control:
This creates a new migration file in prisma/migrations
.
Generate Client
After pushing changes, regenerate the Prisma client:
Note: This runs automatically when starting the development server.
Seeding the Database
The project includes a comprehensive seed file (prisma/seed.ts
) that creates demo data:
- Default users (admin and regular user)
- Common categories (Frontend, Backend, etc.)
- Popular tags (React, Vue, TypeScript, etc.)
- Sample tools with relationships
Feel free to modify the seed data as needed. You can also clear the database and start fresh with npm run db:reset
once you start to feel comfortable with the data in your database.
Customizing Seed Data
To modify the seed data:
- Edit
prisma/seed.ts
- Run
npm run db:reset
to apply changes
Seeding from CSV
To seed from a CSV file, modify prisma/seed.ts
and adjust the code to your needs.
Prisma Client Usage
The Prisma client is initialized as a singleton in services/db.ts
:
Use it in your code:
To learn more about the Prisma client, check out the official documentation.
Prisma Studio
Prisma Studio is a GUI to view and edit data in your database. You can open it by running the following command in the terminal:
This will start the Prisma Studio in your browser. You can use it to view and edit data in your database.
VS Code Integration
The project includes Prisma VS Code extension recommendations for:
- Syntax highlighting
- Auto-completion
- Schema validation
- Quick fixes
Install the recommended extensions for the best development experience.
Last updated on