cloudflare / cloudflare/workerd

apply D1 migrations only fails in production

Open
#5,411 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

We had a fairly complex migration with transactions, it ran fine locally but when we ran it in production, we got

```
πŸš€ Running Wrangler Commands
/usr/local/bin/npx wrangler d1 migrations apply DB --remote
⛅️ wrangler 4.43.0 (update available 4.45.0)
─────────────────────────────────────────────
Migrations to be applied:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ name β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0003_sync_spending_limits.sql β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
? About to apply 1 migration(s)
Your database may not be available to serve requests during the migration, continue?
πŸ€– Using fallback value in non-interactive context: yes
πŸŒ€ Executing on remote database DB (25df52eb-95b6-4a4e-83aa-3880d1f1aff9):
πŸŒ€ To execute on your local development database, remove the --remote flag from your wrangler command.
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ name β”‚ status β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0003_sync_spending_limits.sql β”‚ ❌ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
✘ [ERROR] Migration 0003_sync_spending_limits.sql failed with the following errors:
✘ [ERROR] To execute a transaction, please use the state.storage.transaction() or state.storage.transactionSync() APIs instead of the SQL BEGIN TRANSACTION or SAVEPOINT statements. The JavaScript API is safer because it will automatically roll back on exceptions, and because it interacts correctly with Durable Objects' automatic atomic write coalescing. [code: 7500]
πŸͺ΅ Logs were written to "/home/runner/.config/.wrangler/logs/wrangler-2025-10-24_22-40-25_842.log"
```

This should absolutely have failed locally if you're going to fail it in production.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.