cloudflare / cloudflare/developer-platform
đ BUG: `d1 export` produces unimportable sql files
- Langage dominant
- Aucune donnée de langage
- Ătoiles
- 1
- Forks
- 0
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
### Which Cloudflare product(s) does this pertain to?
D1
### What version(s) of the tool(s) are you using?
3.51.2 [Wrangler]
### What version of Node are you using?
21.6.10
### What operating system and version are you using?
macOS Sonoma 14.4.1
### Describe the Bug
### Observed behavior
When exporting a D1 database with some relations using `npx wrangler d1 export`, it can generate an SQL file that cannot be imported again (`â [ERROR] no such table: main.B`). This is due to INSERTs happening before all tables are created.
I've prepared a minimal reproduction repository: https://github.com/hrueger/d1-export-order
### Expected behavior
All `CREATE TABLE` queries happen first, all `INSERT`s afterwards.
### Steps to reproduce
See https://github.com/hrueger/d1-export-order
in short, you need two tables, where the first table has a foreign key to the second table. Insert one row each, export that and try to import it again using `npx wrangler execute ... --file ...`
In the minimal reproduction there's also a fixed sql file, where the `INSERT` is just moved to the bottom.
### Please provide a link to a minimal reproduction
https://github.com/hrueger/d1-export-order
### Please provide any relevant error logs
```
â [ERROR] no such table: main.B
```
As per our discord conversation on friday, I'm tagging @geelen. Thanks for looking into this!
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par le dĂ©pĂŽt de reproduction minimale et exĂ©cutez `npx wrangler d1 export`, puis essayez dâimporter le fichier gĂ©nĂ©rĂ© avec `npx wrangler execute ... --file ...`. Comparez le SQL gĂ©nĂ©rĂ© avec le fichier SQL corrigĂ© et vĂ©rifiez que les exports comportant des relations de clĂ©s Ă©trangĂšres peuvent ĂȘtre importĂ©s correctement, avec toutes les tables créées avant lâinsertion des lignes.
Rédigé par le modÚle d'indexation à partir du texte de l'issue.
Ăvaluation
- Stack technique
- node.js, sql
- Domaine
- cli, database
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 68/100