Prisma
---
Prisma Configuration
Galsenext uses Prisma
as an ORM (Object-Relational Mapping) to interact with the database. Prisma
simplifies data management and interaction with your PostgreSQL
database.
Prisma Instance Configuration
In Galsenext, Prisma is configured to operate optimally both in development and production modes. The prisma.ts
file located in the /src/lib/
directory is configured to create a unique instance of Prisma that is reused throughout the application, optimizing performance and minimizing database connection issues.
- Creating a Single Instance of Prisma: The Prisma instance is stored in the global variable
global.prisma
to prevent multiple instances from being created in a development environment, which could cause database connection errors. This approach is particularly useful withNext.js
, which uses an automatic module refresh system in development mode. - Prisma Logs Configuration: In development mode (
process.env.NODE_ENV === "development"
), Prisma is configured to display query, error, and warning logs (["query", "error", "warn"]
). In production, only error logs are enabled (["error"]
) to avoid exposing sensitive information. - Environment Check: The code checks if the environment is not in production (
process.env.NODE_ENV !== "production"
). If so, it assigns the Prisma instance toglobal.prisma
to ensure that only one instance is used throughout the application's lifecycle.
Initial Prisma Setup
The Prisma schema file prisma/schema.prisma
is already configured for basic authentication. Here’s how to configure and use Prisma:
1. Initializing Prisma
When you have installed Galsenext, Prisma
is already included. You need to set up your database by following these steps:
Database Migration
To apply the Prisma schema to your database, run the following command:
This command will create the necessary tables for authentication and prepare your database.
2. Modifying the Prisma Schema
The default schema
is sufficient to handle authentication. However, you can modify this file according to your needs. For example, if you want to add models for specific features, edit the prisma/schema.prisma
file:
Applying Changes
After modifying the schema.prisma
file, you need to run a new migration to apply these changes to your database:
This command will update the database by adding the new model or applying other changes you've made to the schema.
Points to Check
- Check the Configuration: Ensure that the
.env
file contains the correct information to connect to your database see Environment Variables Configuration. - Refer to Prisma Documentation: For more details on using
Prisma
and its advanced features, consult the official Prisma documentation.