修复非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