修复非d1部署报错

This commit is contained in:
mtvpls
2026-02-11 16:01:58 +08:00
parent 22b9242e39
commit 7d004ee973
2 changed files with 21 additions and 4 deletions

View File

@@ -67,13 +67,23 @@ jobs:
echo "INIT_CONFIG=${{ secrets.INIT_CONFIG }}" >> $GITHUB_ENV
echo "CONFIG_SUBSCRIPTION_URL=${{ secrets.CONFIG_SUBSCRIPTION_URL }}" >> $GITHUB_ENV
- name: Replace D1 Database ID in wrangler.toml
- name: Configure D1 Database in wrangler.toml
run: |
if [ -n "${{ secrets.D1_DATABASE_ID }}" ]; then
STORAGE_TYPE="${{ secrets.NEXT_PUBLIC_STORAGE_TYPE }}"
if [ "$STORAGE_TYPE" != "d1" ]; then
echo "Storage type is not d1 (current: $STORAGE_TYPE), removing D1 database configuration"
# Remove the entire [[d1_databases]] section including the comment
sed -i '/^# D1 数据库绑定$/,/^database_id = .*$/d' wrangler.toml
# Also remove any remaining [[d1_databases]] block
sed -i '/^\[\[d1_databases\]\]$/,/^$/{ /^\[\[d1_databases\]\]$/d; /^binding = /d; /^database_name = /d; /^database_id = /d; }' wrangler.toml
echo "D1 configuration removed from wrangler.toml"
elif [ -n "${{ secrets.D1_DATABASE_ID }}" ]; then
sed -i 's/REPLACE_WITH_YOUR_D1_DATABASE_ID/${{ secrets.D1_DATABASE_ID }}/g' wrangler.toml
echo "D1 Database ID replaced successfully"
else
echo "D1_DATABASE_ID secret not set, skipping replacement"
echo "⚠️ Storage type is d1 but D1_DATABASE_ID secret not set"
exit 1
fi
- name: Update wrangler.toml with environment variables
@@ -130,6 +140,13 @@ jobs:
- name: Run D1 Database Migrations
run: |
STORAGE_TYPE="${{ secrets.NEXT_PUBLIC_STORAGE_TYPE }}"
if [ "$STORAGE_TYPE" != "d1" ]; then
echo "Storage type is not d1 (current: $STORAGE_TYPE), skipping D1 migrations"
exit 0
fi
if [ -z "${{ secrets.D1_DATABASE_ID }}" ]; then
echo "D1_DATABASE_ID not set, skipping migrations"
exit 0

View File

@@ -115,7 +115,7 @@ Cloudflare Workers 提供免费的边缘计算服务,通过 GitHub Actions 可
- 点击 "Create Token",选择 "Edit Cloudflare Workers" 模板
- 或使用自定义 Token需要以下权限
- Account - Cloudflare Workers Scripts - Edit
- Account - Cloudflare Workers KV Storage - Edit
- Account - D1 - Edit仅在使用 D1 数据库时需要)
- 创建后复制生成的 API Token
- 在 Dashboard 首页右侧可以看到你的 Account ID