From 0d36b46972efc276a2f00ae968d976a3a1dc0be9 Mon Sep 17 00:00:00 2001 From: Mihovil Ilakovac Date: Sun, 4 Aug 2024 21:27:34 +0200 Subject: [PATCH] Fixes template and updates README --- .gitignore | 2 -- README.md | 35 ++++++++++++++++++++++------------- package.json | 2 +- wrangler.toml.example | 8 +++++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 80d56da..a59f3a0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,4 @@ bun.lockb .env app/generated/ -migrations/* -!migrations/.gitkeep prisma/prisma.schema diff --git a/README.md b/README.md index bfb6a56..5591d7b 100644 --- a/README.md +++ b/README.md @@ -21,23 +21,32 @@ $ cd starter $ npm install ``` -1. Create a new D1 database using Wrangler: +1. Copy the `wrangler.toml.example` file to `wrangler.toml` and fill in the necessary values: ```sh -$ npx wrangler@latest d1 create starter # or name it something of your choice +$ cp wrangler.toml.example wrangler.toml ``` -_Note that if you haven't yet used Wrangler, you will be prompted to login to Cloudflare._ + - Replace `$APP_NAME` with your Cloudflare Workers application name + - Replace `$CURRENT_DATE` with the current date like this `2022-01-01` + +2. Create a new D1 database using Wrangler: + +```sh +$ npx wrangler d1 create +``` + +_Note that if you haven't yet used Wrangler, you will be prompted to log in to Cloudflare._ Copy the output of this command, which is structured TOML configuration, into your `wrangler.toml`. -2. Create a new migration file using the `d1 migrations` subcommand: +3. Create a new migration file using the `d1 migrations` subcommand: ```sh -$ npx wrangler d1 migrations create starter create_tables +$ npx wrangler d1 migrations create create_tables ``` -3. Using Prisma's CLI, generate a SQL file based on your Prisma schema in the empty migration file you just created: +4. Using Prisma's CLI, generate a SQL file based on your Prisma schema in the empty migration file you just created: ```sh $ npx prisma migrate diff \ @@ -47,26 +56,26 @@ $ npx prisma migrate diff \ --output migrations/0001_create_tables.sql ``` -4. Generate the necessary Prisma files for Zod validations and any other configured Prisma outputs: +5. Generate the necessary Prisma files for Zod validations and any other configured Prisma outputs: ```sh $ npx prisma generate ``` -5. Apply the migration to your local database: +6. Apply the migration to your local database: ```sh -$ npx wrangler@latest d1 migrations apply cdph-starter +$ npx wrangler d1 migrations apply ``` -6. When you're ready, deploy your application: +7. When you're ready, deploy your application: ```sh -$ npx wrangler@latest deploy +$ npm run deploy ``` -7. Once you've deployed your application, you can apply the migrations to your remote (production) D1 database: +8. Once you've deployed your application, you can apply the migrations to your remote (production) D1 database: ```sh -$ npx wrangler@latest d1 migrations apply cdph-starter --remote +$ npx wrangler d1 migrations apply --remote ``` diff --git a/package.json b/package.json index ff3eb72..1ac3eee 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "dev": "vite", "build": "vite build --mode client && vite build", "preview": "wrangler pages dev ./dist", - "deploy": "$npm_execpath run build && wrangler pages deploy ./dist" + "deploy": "$npm_execpath run build && wrangler pages deploy" }, "private": true, "dependencies": { diff --git a/wrangler.toml.example b/wrangler.toml.example index d374dfd..d0b0e2c 100644 --- a/wrangler.toml.example +++ b/wrangler.toml.example @@ -1,4 +1,10 @@ -name = "cloudflare-d1-prisma-honox-starter" +name = "$APP_NAME" + +pages_build_output_dir = "./dist" + +compatibility_flags = ["nodejs_compat"] + +compatibility_date = "$CURRENT_DATE" [[d1_databases]] binding = "DB"