Skip to content

Commit

Permalink
update cfw example
Browse files Browse the repository at this point in the history
  • Loading branch information
ruheni committed Oct 26, 2023
1 parent 81dd04e commit 6825702
Showing 1 changed file with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,27 @@ We are continuously testing Prisma Accelerate with Cloudflare Workers. [Open an

## 1. Set up your application

Open your terminal and navigate to a location of your choice. Run the following commands to set up your application.
Wrangler is the official Cloudflare Worker CLI. You will use it to develop and deploy to Cloudflare Workers. This guide uses [Wrangler v3](https://developers.cloudflare.com/workers/wrangler/).

Open your terminal and navigate to a location of your choice. First, initialize your project using the [create-cloudflare-cli](https://www.npmjs.com/package/create-cloudflare). To do this, run the following command in your terminal:

```terminal
mkdir prisma-cloudflare-accelerate
cd prisma-cloudflare-accelerate
npm init -y
npm install -D prisma typescript wrangler
npm create cloudflare@latest
```

## 1. Set up Wrangler

Wrangler is the official Cloudflare Worker CLI. You will use it to develop and deploy to Cloudflare Workers. This guide uses [Wrangler v3](https://developers.cloudflare.com/workers/wrangler/).

First, initialize Wrangler. To do this, run the following command in your terminal:
This will ask you a few questions.

```terminal
npx wrangler init
In which directory do you want to create your application?
```

This will ask you a few questions.
Enter the name of your project, for example: `prisma-cloudflare-accelerate`

```terminal
Would you like to use git to manage this Worker? (y/n)
What type of application do you want to create?
```

We want to use Git, so answer yes.
Select the `"Hello World" Worker` option.

```terminal
Would you like to use TypeScript? (y/n)
Expand All @@ -63,12 +58,12 @@ Would you like to use TypeScript? (y/n)
We also want to use TypeScript, so answer yes.

```terminal
Would you like to create a Worker at src/index.ts?
Would you like to use git to manage this Worker? (y/n)
```

Select the `Fetch Handler` option.
We want to use Git, so answer yes.

Once you're done, this will create a `wrangler.toml` file with some initial configuration.
The command this will create a new project with a minimal preset configuration. Once `create-cloudflare-cli` is done, navigate to the project and open it on your editor of choice.

Next, authenticate the Wrangler CLI with your Cloudflare Workers account. To do this, run the following command in your terminal:

Expand All @@ -86,6 +81,14 @@ npx wrangler whoami

Now you're ready to add Prisma to the project.

Install `prisma` as a development dependency:

```terminal
npm install --save-dev prisma
```

Next, initialize Prisma in your project with the following command:

```terminal
npx prisma init
```
Expand All @@ -96,11 +99,11 @@ This creates a Prisma schema in `prisma/schema.prisma`.

**Note:**<br /><br />

This process also creates an `.env` file, but this file has no effect when you use Cloudflare Workers.
`prisma init` also creates an `.env` file, but this file has no effect when you use Cloudflare Workers.

</Admonition>

Inside `prisma/schema.prisma`, add the following schema:
Update your Prisma schema with the following data model:

```prisma
generator client {
Expand All @@ -126,27 +129,27 @@ enum Level {
}
```

This data model will be used to persist logs from your Worker.
The above data model will be used to persist and retrieve logs from your Cloudflare Worker

## 3. Create a repository and push to GitHub
## 3. Update your database schema

To prepare for the steps ahead, let's [create a private repository](https://github.com/new) on GitHub.
Next, initialize your repository, then push your changes up to GitHub.
To map your data model to the database schema, you need to use the `prisma migrate dev` CLI command:

```terminal
git remote add origin https://github.com/<username>/prisma-cloudflare-accelerate
git add .
git commit -m "initial commit"
git push -u origin main
npx prisma migrate dev --name init
```

You're ready to create a project in [Prisma Data Platform](https://console.prisma.io).
The command does two things:

1. It creates a new SQL migration file for this migration
1. It runs the SQL migration file against the database

## 4. Enable Accelerate in Prisma Data Platform

Prisma currently does not work on Cloudflare Workers yet. However, you can use Prisma on Cloudflare Workers through [Prisma Accelerate](/data-platform/accelerate).

To get started:
To get started with Prisma Accelerate:

1. Sign up for a free [Prisma Data Platform account](https://console.prisma.io/)
1. Create a project
1. Navigate to the project you created and enable Accelerate
Expand Down

0 comments on commit 6825702

Please sign in to comment.