Skip to content

[MySQL-kit] Fix CHECK constraint column case mismatch causing MariaDB push failure#5566

Open
karthik-idikuda wants to merge 1 commit intodrizzle-team:mainfrom
karthik-idikuda:fix/mariadb-check-constraint-case
Open

[MySQL-kit] Fix CHECK constraint column case mismatch causing MariaDB push failure#5566
karthik-idikuda wants to merge 1 commit intodrizzle-team:mainfrom
karthik-idikuda:fix/mariadb-check-constraint-case

Conversation

@karthik-idikuda
Copy link
Copy Markdown

Problem

drizzle-kit push exits with code 1 on MariaDB databases containing CHECK constraints. The issue occurs during schema introspection ("Pulling schema from database...").

Root Cause

The CHECK constraints introspection query selects columns with lowercase names:

SELECT tc.table_name, tc.constraint_name, cc.check_clause FROM ...

But the result mapping reads uppercase keys:

const constraintName = checkConstraintRow['CONSTRAINT_NAME'];
const constraintValue = checkConstraintRow['CHECK_CLAUSE'];
const tableName = checkConstraintRow['TABLE_NAME'];

On MySQL, information_schema returns uppercase column names regardless of the query, so this works. On MariaDB (with mysql2 driver), result keys match the case used in the SQL query - returning lowercase keys. This mismatch produces undefined values, which crash when accessing tableInResult.checkConstraint.

Fix

  1. Add explicit AS aliases to the SELECT columns so they always return uppercase keys regardless of the database engine:
SELECT
    tc.table_name AS TABLE_NAME,
    tc.constraint_name AS CONSTRAINT_NAME,
    cc.check_clause AS CHECK_CLAUSE
FROM ...
  1. Uncomment the tableInResult guard (was commented out) to safely skip CHECK constraints for tables not in the result set (e.g., filtered tables), preventing potential runtime crashes.

Reproduction

  1. Use MariaDB (e.g., 10.4.x)
  2. Create a table with a CHECK constraint:
CREATE TABLE inventories (
    id INT AUTO_INCREMENT PRIMARY KEY,
    items LONGTEXT,
    CONSTRAINT items CHECK (json_valid(items))
);
  1. Run npx drizzle-kit push
  2. Observe: exits with code 1 during schema pull

Fixes #5550

… fix MariaDB compatibility

On MariaDB, the mysql2 driver returns result column keys matching the case
used in the SQL query. The CHECK constraints introspection query selected
lowercase column names (table_name, constraint_name, check_clause) but the
result mapping reads uppercase keys (TABLE_NAME, CONSTRAINT_NAME, CHECK_CLAUSE).
This mismatch causes undefined values on MariaDB, leading to a runtime crash
during `drizzle-kit push`.

Fix:
- Add explicit AS aliases to the SELECT columns so they always return
  uppercase keys regardless of the database engine.
- Uncomment the tableInResult guard to safely skip CHECK constraints
  for tables not in the result set (e.g., filtered tables).

Fixes drizzle-team#5550
@karthik-idikuda karthik-idikuda changed the title fix(mysql): add explicit column aliases for CHECK constraint query to fix MariaDB compatibility [MySQL-kit] Fix CHECK constraint column case mismatch causing MariaDB push failure Mar 31, 2026
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]: drizzle-kit push exits with code 1 on MariaDB when CHECK constraints exist (silent failure during schema pull)

1 participant