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 inprisma/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 inlib/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 ofdb push
:
- Create a migration:
- Apply migrations in production:
Docker Database Setup
If you’re using Docker for development, update yourDATABASE_URL
in the .env.docker
file: