drizzle-team / drizzle-team/drizzle-orm
[BUG]: No warning or error when performing a migration with duplicate table columns
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.33.0
### What version of `drizzle-kit` are you using?
0.24.0
### Describe the Bug
Firstly, thanks for putting these great tools [Drizzle ORM et al.] together.
I'm using drizzle-kit to generate a migration with the following schema:
```typescript
...
export const user = sqliteTable('User', {
id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),
type_id: integer('type_id', { mode: 'number' }),
status_id: integer('id', { mode: 'number' }),
first_name: text('first_name'),
last_name: text('last_name'),
uuid: text('uuid').notNull(),
email_addr: text('email_addr').notNull(),
phone_mobile: text('phone_mobile'),
aux: text('aux', { mode: 'json' }),
created_at: text('created_at').default(sql`(CURRENT_TIMESTAMP)`),
updated_at: text('updated_at'),
});
...
```
Note: The `id` column is referenced twice.
This generates the following SQL:
```sql
CREATE TABLE `User` (
`id` integer,
`type_id` integer,
`first_name` text,
`last_name` text,
`uuid` text NOT NULL,
`email_addr` text NOT NULL,
`phone_mobile` text,
`aux` text,
`created_at` text DEFAULT (CURRENT_TIMESTAMP),
`updated_at` text
);
```
The `id` field is overwritten with no warning or error message.
### Expected behavior
Of course, we should all be careful when writing schema files, but shouldn't there be a warning that multiple references to the same column exist in the schema (especially when running a migration via Drizzle-Kit)?
Also, further down the line, the following insert worked (i.e. inserted data) without any indication that `status_id` doesn't exist:
```typescript
await db.insert(user).values([{
type_id: 1,
status_id: 1,
first_name: 'John',
last_name: 'Doe',
uuid: 'unique-id',
email_addr: 'info@example.com',
}]).returning({ insertId: user.id });
```
This insert should fail because with the following SQL:
```sql
INSERT INTO User (id, status_id, first_name, uuid, email_addr) VALUES(2, 1, 'obinwanne', 'unique-id-2sdfsdsf', 'other@example.com')
```
I get the error: **table User has no column named status_id**
### Environment & setup
Mac OS Monterey 12.7.1
Node.js 20.10.0
Contributor guide
Assessment
This issue has not been assessed yet.