Skip to content

Email for professionals and teams

added migration to build script

Hieu Nguyen (Jack)d5a08b0140cb
diff --git a/docs/deployment.md b/docs/deployment.md
index 4ebc640..4ebc752 100644
--- a/docs/deployment.md
+++ b/docs/deployment.md
@@ -8,6 +8,8 @@ This guide covers Cloudflare deployment, runtime configuration, database backups
The deployment flow reads `wrangler.jsonc`, provisions the required Worker bindings, builds the OpenNext Worker, applies D1 migrations, and deploys the app.
+Cloudflare automatically detects `npm run build` as the build command and `npm run deploy` as the deploy command from `package.json`.
+
Keep `wrangler.jsonc` committed. Do not commit `.dev.vars`; enter secrets during Cloudflare setup or keep them in a local `.dev.vars` file.
## Required configuration
@@ -44,15 +46,15 @@ Install dependencies, configure the Cloudflare bindings in `wrangler.jsonc`, and
```bash
npm install
-npm run deploy
+npm run deploy:local
```
-The deploy command builds the OpenNext application and uploads the complete Worker with Wrangler. The complete Worker is required because `worker.ts` also handles inbound email, queues, workflows, and the real-time Durable Object.
+The local deploy command builds the OpenNext application, applies pending D1 migrations, and uploads the complete Worker with Wrangler. The complete Worker is required because `worker.ts` also handles inbound email, queues, workflows, and the real-time Durable Object.
To migrate an existing remote D1 database before deploying, use:
```bash
-npm run deploy:with-migrations
+npm run db:migrate:remote
```
Remote migrations require the target account's `database_id` in your local `wrangler.jsonc`. Do not commit an account-specific database ID to a reusable repository.
diff --git a/open-next.config.ts b/open-next.config.ts
index 898b93f..f875076 100644
--- a/open-next.config.ts
+++ b/open-next.config.ts
@@ -1,6 +1,7 @@
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
export default defineCloudflareConfig({
+ buildCommand: "npm run build:next",
// Uncomment to enable R2 cache,
// It should be imported as:
// `import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache";`
diff --git a/package.json b/package.json
index 835b868..983dcfe 100644
--- a/package.json
+++ b/package.json
@@ -4,12 +4,14 @@
"private": true,
"scripts": {
"dev": "next dev",
- "build": "next build",
+ "build": "opennextjs-cloudflare build",
+ "build:next": "next build",
"start": "next start",
"lint": "next lint",
- "deploy": "opennextjs-cloudflare build && npm run deploy:worker",
- "deploy:worker": "OPEN_NEXT_DEPLOY=true wrangler deploy",
- "deploy:with-migrations": "npm run db:migrate:remote && npm run deploy",
+ "deploy": "npm run db:migrate:remote && opennextjs-cloudflare deploy",
+ "deploy:worker": "opennextjs-cloudflare deploy",
+ "deploy:local": "npm run build && npm run deploy",
+ "deploy:with-migrations": "npm run deploy:local",
"upload": "opennextjs-cloudflare build && OPEN_NEXT_DEPLOY=true wrangler versions upload",
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
"cf-typegen": "wrangler types --env-interface CloudflareEnv ./cloudflare-env.d.ts",