drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.54k stars 578 forks source link

[BUG]: 'left' column name not escaped in index #2425

Closed rogino closed 3 months ago

rogino commented 4 months ago

What version of drizzle-orm are you using?

0.31.0

What version of drizzle-kit are you using?

0.22.1

Describe the Bug

The 0.21.0 schema upgrade has broken one of my indexes:

export const entries = makeTable(
  "entries",
  {
    // ...
    left: timestamp("left"),
  },
  (table) => ({
    leftNullIdx: index("entries_left_null_idx")
      .on(table.left)
      .where(isNull(table.left)),
  })
);

Upon upgrading, it deleted the existing index and created a new one:

CREATE INDEX IF NOT EXISTS "entries_left_null_idx" ON "entries" USING btree (left) WHERE "entries"."left" is null;--> statement-breakpoint

However, Postgres tries to interpret left as a keyword instead of the column name, and thus fails.

Expected behavior

The migration command should quote the column name in USING btree (column_name).

Environment & setup

No response

mandarzope commented 4 months ago

@rogino I had same error for a column name table. It seems restricted keywords can not be the column names.

image
AndriiSherman commented 3 months ago

Should be fixed in drizzle-kit@0.22.5