Skip to main content
Version: Next

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

  1. Choose a database platform:
  2. Follow the installation guide for your selected database.

Step 2: Configure Environment Variables

  1. Open the .env file in the root of your project.
  2. Add or update the DATABASE_URL environment 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]

  1. Run the following command to initialize Prisma:

    npx prisma init

    This will create a prisma directory in your project with the following files:

    • schema.prisma: Your database schema definition file.
  2. Update the schema.prisma file to match your database model requirements.


Step 4: Migrate the Database

  1. Create your database migrations using Prisma:
    npx prisma migrate dev --name init
  2. This will:
    • Generate a migration file in the prisma/migrations folder.
    • Apply the migration to your database.

Step 5: Verify the Database Connection

  1. Use the Prisma Studio to inspect your database:
    npx prisma studio
  2. Open the Prisma Studio URL in your browser and verify that your database is connected.

Troubleshooting

If you encounter any issues:

  • Verify your DATABASE_URL is 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.