SaaS Pilot Docs
  • Introduction
  • Installation
  • 🔌Integrations
    • Database
    • Authentication
    • Stripe
    • Resend
  • 🛠️Operation
    • Admin Access
    • Environment Variables
    • 💬 Discord Community
    • 👋 Connect on Twitter
    • 🧐 Pricing and FAQ
    • 🚀 Live Demo
Powered by GitBook
On this page
  • Overview
  • Generate Database URI
  • Migrate the Schema
  • Additional Tips
  1. Integrations

Database

In this part of the documentation, we will show you how to integrate a Database into the SaaSPilot boilerplate.

Overview

Integrating a database into your SaaSPilot boilerplate is crucial for storing authentication data, user information, and other application data. Below, we provide a universal guide for integrating various types of databases. MongoDB by default, but you can also switch to (MySQL, PostgreSQL, and more...).

To store authentication and other users' data, we used the MongoDB database.

To integrate the Database, all you have to do is generate the Database URL from your database provider and then update this .env variable:

Generate Database URI

Obtain the database connection URI from your database provider. The URI typically includes username, password, host, port, and database name.

Example MongoDB URI:

mongodb://your_username:your_password@your_host:27017/your_database

Example PostgreSQL URI:

postgres://your_username:your_password@your_host:5432/your_database

Update .env File: Open your SaaSPilot project's .env file and update the DATABASE_URL variable with your actual database connection URI.

DATABASE_URL="your_db_connection_string"

Migrate the Schema

We will then use Prisma to migrate your database schema and generate the necessary files:

To Migrate: Run this command to create the tables on your Database.

npx prisma db push

After that, run this command to Generate Prisma Client.

npx prisma generate

The Prisma Client is a type-safe database client auto-generated based on your schema. It allows you to interact with the database in your application.

This is it, and the Database integration is done.

Schema Updates:

Another thing to remember is that every time you update the Prisma Schema, you'll have to run the prisma generate command to keep the Prisma Client in sync.

Additional Tips

  • Schema Updates: Whenever you modify your Prisma schema (the file defining your database models), run npx prisma generate again to update the Prisma Client accordingly.

  • Database Provider Options: Adjust the connection URI format per your database provider's requirements. Ensure compatibility with the database service you are using.

  • MongoDB (Mongoose): Adapt the steps for MongoDB by replacing Prisma commands with Mongoose-specific commands where applicable.

By following these steps, you can seamlessly integrate any database into your SaaSPilot boilerplate, ensuring robust data management capabilities tailored to your application's needs.

PreviousInstallationNextAuthentication

Last updated 5 months ago

🔌