Skip to content

[BUG]: MySQL introspection crashes on functional/expression indexes (COLUMN_NAME is null) #5546

@danielcuque

Description

@danielcuque

Report hasn't been filed before.

  • 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.45.2

What version of drizzle-kit are you using?

0.31.10

Other packages

No response

Describe the Bug

What is the undesired behavior?
drizzle-kit pull crashes with a TypeError: Cannot read properties of null (reading 'camelCase') when introspecting a MySQL 8+ database that contains a unique functional/expression index.

In MySQL 8, when an index is created using an expression (e.g., CREATE UNIQUE INDEX idx ON table ((CASE WHEN col = 1 THEN 1 ELSE NULL END))), the COLUMN_NAME field in INFORMATION_SCHEMA.STATISTICS returns NULL. Instead, the actual expression is stored in the EXPRESSION column.
Currently, mysqlSerializer.ts unconditionally pushes COLUMN_NAME into the index constraints. Later, during TS generation in introspect-mysql.ts, casing(null) is called, crashing the CLI.

What are the steps to reproduce?
I have created a minimal reproduction repository for this issue:
[Replicated error]

(https://github.com/danielcuque/mysql_drizzle)

  1. Clone the repo and run pnpm install
  2. Run pnpm run db:up to start the MySQL container.
  3. Run pnpm run repro:index (which targets a table with a functional index).
  4. (Assuming the silent crash bug is patched locally) You will see the TypeError originating from createTableUniques in introspect-mysql.ts.

What is the desired result?
Drizzle should extract the EXPRESSION column from INFORMATION_SCHEMA.STATISTICS when COLUMN_NAME is null. It should flag these columns in the internals object, and the TS generators should output them wrapped in sql\...`` instead of crashing.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug/fixed-in-betaThis bug has been fixed in beta (or will be soon).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions