drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzle-kit push exits with code 1 on MariaDB when CHECK constraints exist (silent failure during schema pull)

Open
#5,550 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] 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

# drizzle-kit push exits with code 1 on MariaDB when CHECK constraints exist (silent failure during schema pull)

drizzle-kit push fails at "Pulling schema from database..." and exits with code 1, without a useful error message, when targeting MariaDB databases that contain CHECK constraints.

## Environment
- **drizzle-kit:** 0.31.10
- **drizzle-orm:** 0.45.2
- **mysql2:** 3.20.0
- **MariaDB:** 10.4.32
- **Node.js:** reproduced on 25.8.2 and 22.22.2
- **OS:** Windows

## What works
- Direct mysql2 connection works
- drizzle-kit generate works
- drizzle-kit push works against a clean database

## What fails
- drizzle-kit push fails against an existing MariaDB database containing CHECK constraints

# Steps to reproduce
1. Use MariaDB (example: 10.4.x).
2. Create a table with a CHECK constraint, for example:
```sql
CREATE TABLE inventories (
id INT AUTO_INCREMENT PRIMARY KEY,
items LONGTEXT,
CONSTRAINT items CHECK (json_valid(items))
);
```
3. Run:
`npx drizzle-kit push`
4. Observe:
"Pulling schema from database..."
exit code 1
no actionable error printed

### Expected behavior
drizzle-kit should complete introspection or print a clear error.

### Actual behavior
Process exits with code 1 during schema pull.

### Likely root cause
In MySQL introspection for CHECK constraints, selected columns are lower-case (table_name, constraint_name, check_clause), but the result mapping later reads upper-case keys (TABLE_NAME, CONSTRAINT_NAME, CHECK_CLAUSE). On MariaDB/mysql2 this yields undefined values, which can cause a runtime crash when writing into the table map.

##Proposed fix
Either:

Alias SQL columns to upper-case names to match current mapping, or
Read both key variants and guard missing table names.
Example safe mapping:

```js
const constraintName = row.CONSTRAINT_NAME ?? row.constraint_name;
const constraintValue = row.CHECK_CLAUSE ?? row.check_clause;
const tableName = row.TABLE_NAME ?? row.table_name;
if (!tableName || !result[tableName]) continue;
```

Optional SQL alias hardening:
```sql
SELECT
tc.table_name AS TABLE_NAME,
tc.constraint_name AS CONSTRAINT_NAME,
cc.check_clause AS CHECK_CLAUSE
FROM information_schema.table_constraints tc
JOIN information_schema.check_constraints cc
ON tc.constraint_name = cc.constraint_name
WHERE tc.constraint_schema = ? AND tc.constraint_type = 'CHECK';
```
---
I can put together a PR with this fix and a test case if that helps.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.