Skip to content

Commit e3e21f3

Browse files
committed
auto create table for d1 next mode
1 parent 0c93e8b commit e3e21f3

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

examples/overrides/d1-tag-next/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"d1:clean": "wrangler d1 execute NEXT_CACHE_D1 --command \"DROP TABLE IF EXISTS revalidations\"",
11-
"d1:setup": "wrangler d1 execute NEXT_CACHE_D1 --command \"CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);\"",
12-
"build:worker": "pnpm d1:clean && pnpm opennextjs-cloudflare build && pnpm d1:setup",
10+
"build:worker": "pnpm opennextjs-cloudflare build",
1311
"preview:worker": "pnpm opennextjs-cloudflare preview",
1412
"preview": "pnpm build:worker && pnpm preview:worker",
1513
"e2e": "playwright test -c e2e/playwright.config.ts"
@@ -28,4 +26,4 @@
2826
"typescript": "catalog:",
2927
"wrangler": "catalog:"
3028
}
31-
}
29+
}

packages/cloudflare/src/cli/populate-cache/populate-cache.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ export async function populateCache(
8686
if (!config.dangerous?.disableTagCache && !config.dangerous?.disableIncrementalCache && tagCache) {
8787
const name = await resolveCacheName(tagCache);
8888
switch (name) {
89+
case "d1-next-mode-tag-cache": {
90+
logger.info("\nCreating D1 table if necessary...");
91+
92+
runWrangler(
93+
options,
94+
[
95+
"d1 execute",
96+
"NEXT_CACHE_D1",
97+
`--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`
98+
],
99+
{ ...populateCacheOptions, logging: "error" }
100+
)
101+
102+
logger.info("\nSuccessfully created D1 table");
103+
break;
104+
}
89105
case "d1-tag-cache": {
90106
logger.info("\nPopulating D1 tag cache...");
91107

0 commit comments

Comments
 (0)