Database Setup
Database Configuration for CodeChat API
Database configuration is a crucial aspect to ensure the proper functioning of the CodeChat API. This application supports both NoSQL databases (MongoDB) and relational databases (PostgreSQL, MySQL, MariaDB), using Prisma ORM (Object-Relational Mapping) to manage database operations. Prisma ORM makes database access, migration and management easy.
Integrating Prisma ORM
Prisma ORM is integrated to facilitate database operations, enhancing access, migration, and management processes. Depending on your database selection, use the appropriate migration commands:
Note: Ensure proper script file permissions with chmod +x ./scripts/*
Database Setup
Initialize with:
- PostgreSQL:
npx prisma migrate deploy
Deployment Process
For pre-existing relational databases (PostgreSQL, MySQL, or MariaDB), adhere to these steps:
Environment Variable Configuration: Define the
DATABASE_PROVIDER
environment variable to correspond with your chosen relational database (usepostgresql
for PostgreSQL andmysql
for MySQL/MariaDB). This setting informs Prisma ORM of the specific database in use.Schema Deployment: Execute
source ./scripts/run_database_operation_deploy.sh
to implement schema changes. This command, effectively a shortcut forprisma deploy
, inspects and modifies the database schema as needed, while preserving existing data.
Utilizing Prisma Studio
Access and Manage Data
Utilize Prisma Studio to interact with your data models and synchronize them with your database:
npx prisma studio
This configuration ensures seamless integration and management of your database systems, leveraging Prisma ORM's capabilities.
This revised documentation aims to be more structured, clear, and instructive, ensuring a smoother setup process for different database types.