Skip to content

Commit 25a8f4c

Browse files
authored
Feat: automatically create table for D1NextModeTagCache (#486)
* auto create table for d1 next mode * fix deps for overrides app * lint * changeset * review fix
1 parent ced7d46 commit 25a8f4c

File tree

4 files changed

+78
-47
lines changed

4 files changed

+78
-47
lines changed

.changeset/tiny-ways-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
auto create table for D1NextModeTagCache

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@
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"
1614
},
1715
"dependencies": {
18-
"react": "^19.0.0",
19-
"react-dom": "^19.0.0",
20-
"next": "15.1.7"
16+
"react": "catalog:e2e",
17+
"react-dom": "catalog:e2e",
18+
"next": "catalog:e2e"
2119
},
2220
"devDependencies": {
2321
"@opennextjs/cloudflare": "workspace:*",
2422
"@playwright/test": "catalog:",
2523
"@types/node": "catalog:",
26-
"@types/react": "^19",
27-
"@types/react-dom": "^19",
24+
"@types/react": "catalog:e2e",
25+
"@types/react-dom": "catalog:e2e",
2826
"typescript": "catalog:",
2927
"wrangler": "catalog:"
3028
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ 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+
const revalidationsTable = process.env.NEXT_CACHE_D1_REVALIDATIONS_TABLE || "revalidations";
92+
93+
runWrangler(
94+
options,
95+
[
96+
"d1 execute",
97+
"NEXT_CACHE_D1",
98+
`--command "CREATE TABLE IF NOT EXISTS ${JSON.stringify(revalidationsTable)} (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`,
99+
],
100+
{ ...populateCacheOptions, logging: "error" }
101+
);
102+
103+
logger.info("\nSuccessfully created D1 table");
104+
break;
105+
}
89106
case "d1-tag-cache": {
90107
logger.info("\nPopulating D1 tag cache...");
91108

0 commit comments

Comments
 (0)