drizzle-team / drizzle-team/drizzle-orm

[BUG]: ER_DUP_KEYNAME on index field when drizzle-kit push with no alterations

Open
#4,474 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.43.1

### What version of `drizzle-kit` are you using?

0.30.5

### Other packages

_No response_

### Describe the Bug

I'm a bit new to node and js frameworks, but I'm having a weird bug while following a tutorial.

This is my drizzle config:

```
export default {
schema: "./src/server/db/schema.ts",
dialect: "singlestore",
dbCredentials: {
url: env.DATABASE_URL,
},
tablesFilter: ["drive_tutorial_*"],
} satisfies Config;
```

I have this schema in my code:

```
import { int, bigint, text, index, singlestoreTableCreator, timestamp } from "drizzle-orm/singlestore-core";

export const createTable = singlestoreTableCreator( (name) => `drive_tutorial_${name}`)

export const files_table = createTable("files_table", {
id: bigint("id", { mode: "bigint" }).primaryKey().autoincrement(),

ownerId: text("owner_id").notNull(),

name: text("name").notNull(),
size: int("size").notNull(),
url: text("url").notNull(),
parent: bigint("parent", {mode: "bigint"}).notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
}, (t) => {
return [
index("parent_folder_index").on(t.parent),
index("owner_id_index").on(t.ownerId),
]
});
```
A simple table with data regarding a file in a storage.
When I first use `drizzle-kit push` it pushes the schema to SingleStore with no problems.
But, when I tried adding a new field (ownerId, which was not part of the first schema push), when I went to push, I got the following error:

```
drizzle-kit push

No config path provided, using default 'drizzle.config.ts'
Reading config file '[removed]\drive-tutorial\drizzle.config.ts'
[✓] Pulling schema from database...
Reading schema files:
C:\Users\senit\VScodeProjects\ReactCourse\theo\drive-tutorial\src\server\db\schema.ts

Error: Forwarding Error (node-3bf5efad-649f-4367-9878-91bb7de81630-master-0.svc-3bf5efad-649f-4367-9878-91bb7de81630:3306): Duplicate key name 'parent_folder_index'
at PromiseConnection.execute ([removed]\drive-tutorial\node_modules\.pnpm\mysql2@3.14.0\node_modules\mysql2\lib\promise\connection.js:47:22)
at Object.query ([removed]\drive-tutorial\node_modules\.pnpm\drizzle-kit@0.30.6\node_modules\drizzle-kit\bin.cjs:78603:40)
at singlestorePush ([removed]\drive-tutorial\node_modules\.pnpm\drizzle-kit@0.30.6\node_modules\drizzle-kit\bin.cjs:81865:22)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.handler ([removed]\drive-tutorial\node_modules\.pnpm\drizzle-kit@0.30.6\node_modules\drizzle-kit\bin.cjs:92203:9)
at async run ([removed]\drive-tutorial\node_modules\.pnpm\drizzle-kit@0.30.6\node_modules\drizzle-kit\bin.cjs:91408:7) {
code: 'ER_DUP_KEYNAME',
errno: 1061,
sql: 'CREATE INDEX `parent_folder_index` ON `drive_tutorial_files_table` (`parent`);',
sqlState: '42000',
sqlMessage: "Forwarding Error (node-3bf5efad-649f-4367-9878-91bb7de81630-master-0.svc-3bf5efad-649f-4367-9878-91bb7de81630:3306): Duplicate key name 'parent_folder_index'"
}
```

this was the first time I encountered this error. I decided to drop my indexes directly on the database, and when the indexes were removed, the push went normally. Right after this push, I tried pushing again, just to check, and got the same error. Apparently, drizzle is trying to create the index on every push, regardless of it already being there or not, and that is breaking my DB Pushes.

This may either be a bug or me doing something wrong, as I'm new to this library, but I've trying to solve this for a while and got no clue on how to solve this problem. I found a simillar issue here but it was closed by the op without a solution, so I decided to open the issue here

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.