[PR #7059] fix(cli): use json() for MySQL array and JSON field for Drizzle #7048

Open
opened 2026-03-13 13:22:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7059
Author: @ax-at
Created: 12/30/2025
Status: 🔄 Open

Base: canaryHead: fix/drizzle-mysql-json-and-array-types


📝 Commits (2)

  • 4c72271 fix(cli): use json() with $type() for MySQL array and JSON field types in Drizzle schema
  • 7502f3c Merge branch 'canary' into fix/drizzle-mysql-json-and-array-types

📊 Changes

3 files changed (+226 additions, -4 deletions)

View changed files

📝 packages/cli/src/generators/drizzle.ts (+12 -4)
packages/cli/test/__snapshots__/auth-schema-mysql-json-array.txt (+105 -0)
📝 packages/cli/test/generate.test.ts (+109 -0)

📄 Description

MySQL's text() in drizzle-orm only accepts { enum?: TEnum } config and
MySQL's json() doesn't accept any config object. The { mode: "json" }
syntax is only valid for SQLite, not MySQL.

Additionally, add .$type() for proper TypeScript inference:

  • number[] uses .$type<number[]>()
  • string[] uses .$type<string[]>()
  • json uses .$type<Record<string, unknown>>()

Changes:

  • Change number[] type mapping to json() with $type<number[]>()
  • Change string[] type mapping to json() with $type<string[]>()
  • Change json type mapping to json() with $type<Record<string, unknown>>()
  • Add tests for MySQL string array, number array, and JSON fields
  • Add snapshot test for MySQL JSON/array field types

Summary by cubic

Fix MySQL Drizzle schema generation by mapping array and JSON fields to json().$type() and removing the unsupported { mode: "json" } for MySQL. Ensures valid MySQL schemas and correct TypeScript types.

  • Bug Fixes
    • Map number[]/string[] and JSON to json("").$type() for MySQL; remove { mode: "json" }.
    • Ensure mysql-core imports include json when arrays are used without JSON fields.
    • Add tests and a snapshot covering MySQL arrays/JSON and absence of { mode }.

Written for commit 7502f3ca39287599ddaf56520a65b8d3af29a7b6. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7059 **Author:** [@ax-at](https://github.com/ax-at) **Created:** 12/30/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `fix/drizzle-mysql-json-and-array-types` --- ### 📝 Commits (2) - [`4c72271`](https://github.com/better-auth/better-auth/commit/4c72271f1195838e153317230ceb540322c4f747) fix(cli): use json() with $type<T>() for MySQL array and JSON field types in Drizzle schema - [`7502f3c`](https://github.com/better-auth/better-auth/commit/7502f3ca39287599ddaf56520a65b8d3af29a7b6) Merge branch 'canary' into fix/drizzle-mysql-json-and-array-types ### 📊 Changes **3 files changed** (+226 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/src/generators/drizzle.ts` (+12 -4) ➕ `packages/cli/test/__snapshots__/auth-schema-mysql-json-array.txt` (+105 -0) 📝 `packages/cli/test/generate.test.ts` (+109 -0) </details> ### 📄 Description MySQL's text() in drizzle-orm only accepts { enum?: TEnum } config and MySQL's json() doesn't accept any config object. The { mode: "json" } syntax is only valid for SQLite, not MySQL. Additionally, add .$type<T>() for proper TypeScript inference: - number[] uses .$type<number[]>() - string[] uses .$type<string[]>() - json uses .$type<Record<string, unknown>>() Changes: - Change number[] type mapping to json() with $type<number[]>() - Change string[] type mapping to json() with $type<string[]>() - Change json type mapping to json() with $type<Record<string, unknown>>() - Add tests for MySQL string array, number array, and JSON fields - Add snapshot test for MySQL JSON/array field types <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix MySQL Drizzle schema generation by mapping array and JSON fields to json().$type<T>() and removing the unsupported { mode: "json" } for MySQL. Ensures valid MySQL schemas and correct TypeScript types. - **Bug Fixes** - Map number[]/string[] and JSON to json("<name>").$type<T>() for MySQL; remove { mode: "json" }. - Ensure mysql-core imports include json when arrays are used without JSON fields. - Add tests and a snapshot covering MySQL arrays/JSON and absence of { mode }. <sup>Written for commit 7502f3ca39287599ddaf56520a65b8d3af29a7b6. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:22:25 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7048