背景
Qingyu’Blog 最初使用 Cloudflare KV 作为存储后端,后来迁移到 D1(SQLite):迁移方式
本地执行
预览(推荐先执行)
正式迁移
GitHub Actions
- Actions 标签页 → Migrate KV to D1
- Run workflow → 选择
migrate模式
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
从 KV 存储迁移到 D1 数据库
| 特性 | KV | D1 |
|---|---|---|
| 一致性 | 最终一致性 | 强一致性 |
| 查询 | Key-Value | SQL |
| 性能 | 较慢 | 边缘 SQLite |
export CLOUDFLARE_ACCOUNT_ID="你的账户ID"
export CLOUDFLARE_API_TOKEN="你的API Token"
export BLOG_KV_ID="KV命名空间ID"
export BLOG_D1_ID="D1数据库ID"
node scripts/migrate-kv-to-d1.mjs --dry-run
node scripts/migrate-kv-to-d1.mjs
migrate 模式| KV Key | D1 表 | 说明 |
|---|---|---|
posts | posts | 文章 |
comments:{id} | comments | 评论 |
stats:{id} | stats | 统计 |
admin:auth | admin_auth | 管理员密码 |
admin:sessions | admin_sessions | 会话 |
settings:* | site_settings | 设置 |
# 检查文章数量
npx wrangler d1 execute blog --remote --command "SELECT COUNT(*) FROM posts"
# 检查评论数量
npx wrangler d1 execute blog --remote --command "SELECT COUNT(*) FROM comments"
