Database Setup
Configuring your database is an essential step in building your SaaS application. SaaS Developer Templates supports multiple databases and uses Prisma ORM to manage data efficiently.
Supported Databases
You can use the following databases with SaaS Developer Templates (with Prisma's support):
- MongoDB
- PostgreSQL
- MySQL
- SQLite
For best performance, we recommend using PostgreSQL or MySQL in production.
Step 1: Install Database
- Choose a database platform:
- Follow the installation guide for your selected database.
Step 2: Configure Environment Variables
- Open the .envfile in the root of your project.
- Add or update the DATABASE_URLenvironment variable to match your database connection string.
Example Connection Strings:
PostgreSQL:
DATABASE_URL=postgresql://user:password@localhost:5432/your_database
MySQL:
DATABASE_URL=mysql://user:password@localhost:3306/your_database
SQLite:
DATABASE_URL=file:./dev.db
MongoDB:
DATABASE_URL=mongodb+srv://user:password@cluster.mongodb.net/your_database
Replace user, password, localhost, port, and your_database with your actual database credentials.
Step 3: Initialize Prisma [learning purpose only, file is already in place]
- 
Run the following command to initialize Prisma: npx prisma initThis will create a prismadirectory in your project with the following files:- schema.prisma: Your database schema definition file.
 
- 
Update the schema.prismafile to match your database model requirements.
Step 4: Migrate the Database
- Create your database migrations using Prisma:
npx prisma migrate dev --name init
- This will:
- Generate a migration file in the prisma/migrationsfolder.
- Apply the migration to your database.
 
- Generate a migration file in the 
Step 5: Verify the Database Connection
- Use the Prisma Studio to inspect your database:
npx prisma studio
- Open the Prisma Studio URL in your browser and verify that your database is connected.
Troubleshooting
If you encounter any issues:
- Verify your DATABASE_URLis correct.
- Ensure your database server is running.
- Check the logs for errors when running migrations or starting the server.
For more details, visit Prisma's documentation.
Your database is now configured! 🎉 Proceed to the next step: Set Up Authentication.