Prerequisites
Before you begin, ensure you have the following installed:- Node.js (v16 or higher)
- npm or yarn package manager
- Docker and Docker Compose (for database)
- PostgreSQL (if not using Docker)
Installation Steps
Install Dependencies
Install all required npm packages:This will install key dependencies including:
@prisma/client(v6.19.2) - Prisma ORM client@prisma/adapter-pg(v7.4.2) - PostgreSQL adapterprisma(v7.4.2) - Prisma CLI and toolingpg(v8.19.0) - PostgreSQL driverdotenv(v17.3.1) - Environment variable management
Configure Environment Variables
Create a
.env file in the project root with your database connection settings:.env
The
DATABASE_URL format is: postgresql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]?schema=publicEnvironment Variable Breakdown
| Variable | Description | Default Value |
|---|---|---|
DATABASE_URL | PostgreSQL connection string | Required |
Start the Database
Use Docker Compose to start the PostgreSQL database:Verify the database is running:You should see the
postgres service running and healthy.Run Database Migrations
Apply Prisma migrations to set up your database schema:Or if you’re in development:This creates all necessary tables:
users, user_types, faces, devices, and access_logs.Database Connection Configuration
Prisma Configuration
The project uses a custom Prisma configuration file (prisma.config.ts) that defines the schema location and migration paths:
prisma.config.ts
The configuration automatically loads environment variables using
dotenv/config, so your .env file will be read automatically.Connection String Formats
Verifying Your Setup
Check Database Connection
Test your database connection using Prisma Studio:http://localhost:5555 where you can view and manage your database.
Verify Schema
Check that all tables were created correctly:Troubleshooting
Connection Refused
Solution: Ensure PostgreSQL is running:Authentication Failed
Solution: Verify your credentials in the.env file match the Docker Compose configuration:
- Check
POSTGRES_USERindocker-compose.ymlmatches the username inDATABASE_URL - Check
POSTGRES_PASSWORDindocker-compose.ymlmatches the password inDATABASE_URL - Check
POSTGRES_DBindocker-compose.ymlmatches the database name inDATABASE_URL
Migration Errors
Solution: Create the database first:Port Already in Use
Solution: Either stop the conflicting service or change the port indocker-compose.yml:
docker-compose.yml
DATABASE_URL:
Prisma Client Not Found
Solution: Regenerate the Prisma Client:Schema Out of Sync
Solution: Apply pending migrations:Next Steps
Prisma Client Usage
Learn how to use Prisma Client for database operations
Docker Configuration
Deep dive into the Docker Compose setup
Database Schema
Explore the complete database schema
API Reference
View model API reference and usage examples