Skip to content

fix(drizzle-kit): handle MySQL functional/expression indexes in introspection#5548

Open
cyphercodes wants to merge 1 commit intodrizzle-team:mainfrom
cyphercodes:main
Open

fix(drizzle-kit): handle MySQL functional/expression indexes in introspection#5548
cyphercodes wants to merge 1 commit intodrizzle-team:mainfrom
cyphercodes:main

Conversation

@cyphercodes
Copy link
Copy Markdown

Bug Description

MySQL 8+ functional indexes have COLUMN_NAME = null in INFORMATION_SCHEMA.STATISTICS with the actual expression stored in the EXPRESSION column. This caused drizzle-kit pull to crash with:

TypeError: Cannot read properties of null (reading 'camelCase')

when introspecting databases with functional/expression indexes.

Changes

mysqlSerializer.ts

  • Check for null COLUMN_NAME and use EXPRESSION column instead for functional indexes
  • Track expression columns in internals.indexes for proper TypeScript generation
  • Skip entries where both COLUMN_NAME and EXPRESSION are null

introspect-mysql.ts

  • Updated createTableIndexes and createTableUniques to accept schema parameter
  • Expression columns are now wrapped in sql\...`instead oftable.column`

Example

Before (crash):

CREATE UNIQUE INDEX idx ON table ((CASE WHEN col = 1 THEN 1 ELSE NULL END));

After (works):

unique("idx").on(sql`CASE WHEN col = 1 THEN 1 ELSE NULL END`)

Testing

This fix was tested against the reproduction case provided in #5546.

Fixes #5546

…spection

MySQL 8+ functional indexes have COLUMN_NAME = null in INFORMATION_SCHEMA.STATISTICS
with the actual expression stored in the EXPRESSION column. This caused drizzle-kit pull
to crash with 'Cannot read properties of null (reading camelCase)' when introspecting
databases with functional indexes.

Changes:
- mysqlSerializer.ts: Check for null COLUMN_NAME and use EXPRESSION column instead
- mysqlSerializer.ts: Track expression columns in internals.indexes for TS generation
- introspect-mysql.ts: Handle expression columns by wrapping in sql`...` instead of table.column

Fixes drizzle-team#5546
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant