Database

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

Overview

Integrating a database into your SaaSBold 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. PostgreSQL by default, but you can also switch to (MySQL, MongoDB, and more...).

To store authentication and other users' data, we used the PostgreSQL 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 PostgreSQL URI:

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

Example MongoDB URI:

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

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

DATABASE_URL="your_db_connection_string"

Check out a tutorial on How to get a PostgreSQL Database URL.

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 SaaSBold boilerplate, ensuring robust data management capabilities tailored to your application's needs.

Last updated