cloudflare / cloudflare/developer-platform

🐛 BUG: `d1 export` produces unimportable sql files

Đang mở
#41 4 bình luận 5 reaction 0 người được giao Xem trên GitHub
product:d1
Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
1
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với repository tái hiện tối thiểu và chạy `npx wrangler d1 export`, sau đó thử import tệp đã tạo bằng `npx wrangler execute ... --file ...`. So sánh SQL đã tạo với tệp SQL đã sửa và xác minh rằng các bản export có quan hệ khóa ngoại có thể được import thành công, với tất cả các bảng được tạo trước khi các hàng được chèn vào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
node.js, sql
Lĩnh vực
cli, database
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.