workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

🐛 BUG: Exporting local d1 sql to remote fails only when a previous attempt to apply a migration failed.

Open matrs opened this issue 1 year ago • 1 comments

Which Cloudflare product(s) does this pertain to?

D1

What version(s) of the tool(s) are you using?

3.67.1

What version of Node are you using?

18.19.0

What operating system and version are you using?

Linux Manjaro (arch)

Describe the Bug

Observed behavior

I was applying a migration and failed (this migration succeeds locally, see bug) and then i try to export the local d1 db with d1 export and execute it in remote:

#this failed
npx wrangler d1 migrations apply prods --remote
#this works
npx wrangler d1 export prods --output local_prods.sql --local
#this fails
npx wrangler d1 execute prods --file local_prods.sql --remote
✘ [ERROR] table d1_migrations already exists at offset 14: SQLITE_ERROR

The db info after the failed migration was applied increased to 12kb to 25kb, no data table was created.

if i do this from a freshly created db, without the failed attempt to apply the migration remotely, it works:

npx wrangler d1 execute prods --file local_prods.sql --remote

My first though was if there was a way to reset the database on which the failed migration was applied, and it seems there is not.

Expected behavior

Steps to reproduce

Please provide the following:

  • A minimal working subset of your worker code
  • A minimal working subset of your wrangler.toml
  • Commands used to start your local dev server, including custom env and cli args
  • Steps to be performed in the browser, curl commands, or a test we can run that reliably fails (at least a percent of the time)

A git repo we can clone and run a test suite on, or which has a README with step-by-step instructions, is even better. In this case, please use the field below to provide a link to the minimal repro.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

matrs avatar Jul 26 '24 16:07 matrs

Not really, I found this in a test DB, so I just did what I described in the issue.

On Fri, Oct 11, 2024 at 5:46 PM maggie44 @.***> wrote:

Did you find a solution to restore functionality of an existing DB? Deleting and starting over isn't really an option for me.

— Reply to this email directly, view it on GitHub https://github.com/cloudflare/workers-sdk/issues/6348#issuecomment-2408100552, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC7MOYXCK4HTNPHPDVMULODZ3A2MDAVCNFSM6AAAAABLQ2UDRSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMBYGEYDANJVGI . You are receiving this because you authored the thread.Message ID: @.***>

matrs avatar Oct 11 '24 22:10 matrs

wrangler d1 export does export the entire database including a table which tracks applied migrations if they have been applied. This table can conflict with existing databases, but this will not happen with newly created databases. It seems safer to fail in the case that there is conflicting data in the target database rather than overwrite.

joshthoward avatar Jan 07 '25 20:01 joshthoward