Skip to content

Commit

Permalink
feat: static ip docs (#5807)
Browse files Browse the repository at this point in the history
* feat: static ip docs

* Optimised images with calibre/image-actions

* remove the necessity of a publicly hosted database

* Update content/300-accelerate/650-troubleshoot.mdx

Co-authored-by: Petra Donka <[email protected]>

* Update content/300-accelerate/600-faq.mdx

Co-authored-by: Petra Donka <[email protected]>

* feat: simplify callouts and point to faq

* enhance: benefit of using static ip and avoid fluff

* enhance: polish benefits of static ips

* Update content/300-accelerate/600-faq.mdx

Co-authored-by: Petra Donka <[email protected]>

* feat: Accelerate getting started copy (#5838)

* Update content/300-accelerate/600-faq.mdx

Co-authored-by: Petra Donka <[email protected]>

* Update content/300-accelerate/600-faq.mdx

* Update content/300-accelerate/580-local-development.mdx

* Update content/300-accelerate/600-faq.mdx

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Petra Donka <[email protected]>
Co-authored-by: Luan van der Westhuizen <[email protected]>
  • Loading branch information
4 people authored Apr 9, 2024
1 parent 620d611 commit 310fdc4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
71 changes: 38 additions & 33 deletions content/300-accelerate/200-getting-started.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: 'Getting started'
metaTitle: 'Getting started with Accelerate'
metaDescription: 'Learn how to get up and running with Accelerate.'
metaTitle: 'Getting started with Prisma Accelerate'
metaDescription: 'Learn how to get up and running with Prisma Accelerate.'
tocDepth: 3
toc: true
---
Expand All @@ -14,52 +14,46 @@ toc: true

To get started with Accelerate, you will need the following:

- A GitHub account.
- A [Prisma Data Platform workspace](https://console.prisma.io).
- A project that uses [Prisma Client](/orm/prisma-client) `4.16.1` or higher. If your project is using interactive transactions, you need to use `5.1.1` or higher. (We always recommend using the latest version of Prisma.)
- A hosted PostgreSQL, MySQL/MariaDB, PlanetScale, CockroachDB, or MongoDB database.

## 1. Enable Accelerate in a project
## 1. Enable Accelerate

In order to enable Accelerate, you can log in to [Prisma Data Platform](https://pris.ly/pdp) and create a new project. Follow the instructions in the UI to add Accelerate.
Navigate to your Prisma Data Platform project, choose an environment, and enable Accelerate by providing your database connection string and selecting the region nearest your database.

At the end of the setup process, you'll obtain a connection string that connects to Accelerate. This connection string also contains an API key that you need to use when configuring Prisma Client to use Accelerate.

## 2. Use Accelerate in your application
<Admonition>

To get started using Accelerate, we recommend using the [latest version of Prisma ORM](https://github.com/prisma/prisma/releases/).
If you require IP allowlisting or firewall configurations with trusted IP addresses, enable Static IP for enhanced security

### 2.1. Update your database connection string

After enabling Accelerate in your project and creating a new API key, you should be given an Accelerate connection string.
</Admonition>

To use this connection string, update the `datasource` block's `url` field in your Prisma schema:
## 2. Add Accelerate to your application

```prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
```
### 2.1. Update your database connection string

Most likely, as shown above, your database connection string in defined in a `.env` file rather than hard-coded into the schema file.
Once enabled, you'll be prompted to generate an API key that you'll use in your new Accelerate connection string to authenticate requests.

Update that variable to use the new Accelerate connection string:
Replace your direct database url with your new Accelerate connection string.

```env file=.env
# __API_KEY__ is a unique API key that Accelerate generates and automatically assigns to a project.
# New Accelerate connection string with generated API_KEY
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__"
# Previous connection string
# Previous (direct) database connection string
# DATABASE_URL="postgresql://user:password@host:port/db_name?schema=public"
```

Prisma Migrate and Introspection do not work with a `prisma://` connection string. In order to continue using these features add a new variable to the `.env` file named `DIRECT_DATABASE_URL` whose value is the direct database connection string:
Your updated connection string will be used as the datasource `url` in your Prisma schema file;

<Admonition>

As of Prisma version `5.2.0` you can use Prisma Studio with the Accelerate connection string.
```prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
```

</Admonition>
Prisma Migrate and Introspection do not work with a `prisma://` connection string. In order to continue using these features add a new variable to the `.env` file named `DIRECT_DATABASE_URL` whose value is the direct database connection string:

```env file=.env highlight=3;add
DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__"
Expand All @@ -82,10 +76,16 @@ Migrations and introspections will use the `directUrl` connection string rather
### 2.2. Install the Accelerate Prisma Client extension

Run the following command to install the Accelerate extension for Prisma Client:
<Admonition>

💡 Accelerate requires [Prisma Client](/orm/prisma-client) version `4.16.1` or higher and [`@prisma/extension-accelerate`](https://www.npmjs.com/package/@prisma/extension-accelerate) version `1.0.0` or higher

</Admonition>

Install the latest version of Prisma Client and Accelerate Prisma Client extension

```terminal
npm install @prisma/extension-accelerate
npm install @prisma/client@latest @prisma/extension-accelerate
```

### 2.3. Generate Prisma Client for Accelerate
Expand Down Expand Up @@ -122,10 +122,9 @@ If your Prisma version is below `5.0.0`, generate Prisma Client with the `--data

</Admonition>

### 2.4. Extend your Prisma Client instance to add the Accelerate extension
### 2.4. Extend your Prisma Client instance with the Accelerate extension

To use Accelerate, you must extend Prisma Client with the Accelerate extension.
Extend your Prisma Client instance to add the Accelerate extension:
Add the following to extend your existing Prisma Client instance with the Accelerate extension:

```ts
import { PrismaClient } from '@prisma/client'
Expand Down Expand Up @@ -192,3 +191,9 @@ You should now see improved performance for your cached queries.
For information about which strategy best serves your application, see [Select a cache strategy](/accelerate/caching#selecting-a-cache-strategy).

</Admonition>

<Admonition>

As of Prisma version `5.2.0` you can use Prisma Studio with the Accelerate connection string.

</Admonition>
2 changes: 1 addition & 1 deletion content/300-accelerate/580-local-development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ toc: true

<TopBlock>

Prisma Accelerate is designed to scale database connections efficiently in production environments. Prisma Accelerate also provides a global cache to reduce the load on your database and reduce query response time. To leverage Prisma Accelerate, it is essential to utilize a publicly accessible database.
Prisma Accelerate efficiently scales production traffic with integrated connection pooling and a global database cache.

In development environments, you may want to use a local database to minimize expenses. Furthermore, you may consider extending Prisma Client with the Accelerate client extension once so that you can use a local database in development and a hosted database with Accelerate’s connection pooling and caching enabled. This eliminates the need for conditional logic to switch clients between development and production.

Expand Down
12 changes: 12 additions & 0 deletions content/300-accelerate/600-faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ toc: true

<TopBlock>Below are frequently asked questions about Accelerate.</TopBlock>

## When should I enable static IP for Prisma Accelerate?

A static IP address is an IPv4 or an IPv6 address that is fixed. Unlike dynamic IP addresses, which can change unpredictably, traffic from static IP addresses can be easily identified. Enable static IP for Accelerate when your security setup requires IP allowlisting or if you're implementing firewalls that only permit access from trusted IPs, ensuring controlled and secure database connections.

![What is a static IP](./images/static-ip.png)

For databases using IP allowlisting, enable static IP for Accelerate in your specified project environment, and add the obtained IP address to your database's allowlist to ensure authorized access from Accelerate.

![](./images/result-of-adding-static-ip-to-accelerate.png)

> ℹ️ To enable static IP support for Accelerate within your existing or new project environment, your workspace will need to be on our **Pro** or **Business** plans. Take a look at the [pricing page](https://www.prisma.io/pricing) for more information.
## Why do I sometimes see unexpected cache behavior?

Accelerate's cache performs best when it observes a higher load from a project. Many cache operations, such as committing data to cache and refreshing stale data, happen asynchronously. When benchmarking Accelerate, we recommend doing so with loops or a load testing approach. This will mimic higher load scenarios better and reduce outliers from low frequency operations.
Expand Down
4 changes: 2 additions & 2 deletions content/300-accelerate/650-troubleshoot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ This error indicates that Prisma Accelerate cannot establish a connection to you

#### Database Not Publicly accessible

Prisma Accelerate currently requires the database to be publicly accessible. If your database is behind a VPC, or access is restricted to specific IP addresses, this error may occur.
If your database is behind a VPC, or access is restricted to specific IP addresses, this error may occur.

**Suggested solution:** Ensure your database is publicly accessible, if not, allow public access. Please note this is only an interim requirement, Static IPs are coming soon and will alleviate the need for complete public access if that’s not desirable.
**Suggested solution:** Enable static IP within your Accelerate configuration in your project environment. After you enable static IP, add the obtained IP address in your database firewall's IP allowlist. This will ensure that Accelerate can connect to your database. To learn more about static IP, see this [FAQ](/accelerate/faq#when-do-i-have-to-enable-static-ip-for-prisma-accelerate).

#### Unreachable Database Host/Port

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/300-accelerate/images/static-ip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion content/400-pulse/200-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ toc: true

</Admonition>

You'll need the following to integrate Pulse into your application:
To get started with Pulse, you will need the following:

- A [Prisma Data Platform workspace](https://console.prisma.io).
- [Prisma Client](/orm/prisma-client) version `4.16.1` or higher and [`@prisma/extension-pulse`](https://www.npmjs.com/package/@prisma/extension-pulse) version `1.0.1` or higher.
Expand Down

0 comments on commit 310fdc4

Please sign in to comment.