Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the template #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ bun.lockb
.env

app/generated/
migrations/*
!migrations/.gitkeep
prisma/prisma.schema
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this missing step, setting up the 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 <your-database-name>
```

_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 <your-database-name> 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 \
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing latest since npx will use the version listed in the package.json anyways.

$ npx wrangler d1 migrations apply <your-database-name>
```

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 <your-database-name> --remote
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 7 additions & 1 deletion wrangler.toml.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
name = "cloudflare-d1-prisma-honox-starter"
name = "$APP_NAME"

pages_build_output_dir = "./dist"

compatibility_flags = ["nodejs_compat"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worker wouldn't build for me without this flag.


compatibility_date = "$CURRENT_DATE"

[[d1_databases]]
binding = "DB"
Expand Down