From 68257020dfbaf865e6f3c37414beeb744db2c89c Mon Sep 17 00:00:00 2001 From: ruheni Date: Thu, 26 Oct 2023 16:30:32 +0200 Subject: [PATCH] update cfw example --- .../450-deploy-to-cloudflare-workers.mdx | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/content/300-guides/200-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx b/content/300-guides/200-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx index d9e450a869..20f3be8ff7 100644 --- a/content/300-guides/200-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx +++ b/content/300-guides/200-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx @@ -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) @@ -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: @@ -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 ``` @@ -96,11 +99,11 @@ This creates a Prisma schema in `prisma/schema.prisma`. **Note:**

-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. -Inside `prisma/schema.prisma`, add the following schema: +Update your Prisma schema with the following data model: ```prisma generator client { @@ -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//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