cloudflare / cloudflare/developer-platform

D1 doesn't include enough information when foreign key constraints fail

Đang mở
#6 5 bình luận 6 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ả

I have this Drizzle schema
```ts
export const users = sqliteTable(
"users",
{
id: text("id").primaryKey(),
name: text("name").notNull(),
// ...
})

export const accounts = sqliteTable(
"accounts",
{
id: text("id").primaryKey(),
userId: text("userId")
.notNull()
.references(() => users.id),
// ...
})
```

Which produces this migration
```sql
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL
);

CREATE TABLE `accounts` (
`id` text PRIMARY KEY NOT NULL,
`accountId` text NOT NULL,
`userId` text NOT NULL,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
```

When I try to delete a user that has accounts, I get this error:
```ts
SqliteError: FOREIGN KEY constraint failed
at proxy (/home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:64941:47)
at /home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:74841:32
at dispatch (/home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:72483:27)
at /home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:72484:24
at /home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:71944:15
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async dispatch (/home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:72483:21)
at async cors2 (/home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:73520:9)
at async dispatch (/home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:72483:21)
at async /home/vlady/code/gyarns/node_modules/.pnpm/drizzle-kit@0.30.2/node_modules/drizzle-kit/bin.cjs:74793:9 {
code: 'SQLITE_CONSTRAINT_FOREIGNKEY'
}
```
I get the same `FOREIGN KEY constraint failed` error in the D1 dashboard when I use the GUI to delete a user with an account. These errors are hard to debug in big schemas because they don't say exactly which constraint failed.

How can we include a name of the constraint in the error?

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 schema TypeScript và migration SQLite được tạo như trong báo cáo, sau đó tái hiện thao tác xóa người dùng bị lỗi trong D1 dashboard. Payload không nêu tên tệp hoặc test nào của repository; được coi là hoàn tất khi lỗi foreign-key xác định constraint cụ thể liên quan thay vì chỉ báo cáo một lỗi chung chung.

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

Đánh giá

Công nghệ
sqlite, typescript
Lĩnh vực
databases
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/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.