Database Management
Working with PostgreSQL and Prisma in ProStack
ProStack uses PostgreSQL as its database and Prisma as the ORM (Object-Relational Mapping) tool for database operations.
Database Setup
Before you can use the database, make sure you have:
- Installed PostgreSQL on your system
- Created a database for your application
- Updated the
DATABASE_URL
in your.env
file
Prisma Schema
The Prisma schema defines your database models and relationships. In ProStack, the schema is located in prisma/schema.prisma
.
When you modify the schema, you need to synchronize these changes with your database.
Database Commands
ProStack includes several commands to manage your database:
Working with Prisma Client
ProStack provides a configured Prisma client in lib/db.ts
that you can import and use in your application:
Database Relationships
Prisma makes it easy to work with relationships between tables. For example, to fetch a user with their posts:
Using Transactions
For operations that require multiple database changes, use transactions to ensure data consistency:
Database Migrations
In production environments, it’s recommended to use migrations instead of db push
:
- Create a migration:
- Apply migrations in production:
Docker Database Setup
If you’re using Docker for development, update your DATABASE_URL
in the .env.docker
file:
Next Steps
Was this page helpful?