# Database

### 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...).

{% hint style="success" %}
To store authentication and other users' data, we used the **MongoDB** database.
{% endhint %}

To integrate the Database, all you have to do is generate the Database URL from your database provider and then update this <mark style="color:purple;">**.env**</mark> 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 <mark style="color:purple;">`.env`</mark> file and update the <mark style="color:purple;">`DATABASE_URL`</mark> 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 <mark style="color:purple;">**`prisma generate`**</mark> 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 <mark style="color:purple;">**`npx prisma generate`**</mark> 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.
