drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: database-level JSON schema enforcement for typed JSON/JSONB columns

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

Description

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

Currently, if I'm understanding correctly, Drizzle's JSON typing/validation primarily exists at the application layer. This means external systems or direct database access can still write invalid JSON structures that bypass the expected schema.

Given that Zod now supports conversion to [JSON Schema](https://zod.dev/json-schema) It would be fantastic if Drizzle could optionally leverage this to emit database-level JSON validation constraints for supported databases.

Potential flow:

- define JSON schema using Zod
- supply that schema to something like jsonb().validator(schema)
- infer TypeScript types in Drizzle
- generate JSON Schema from Zod

MySQL would enforce this via `JSON_SCHEMA_VALID` and PostgreSQL via extensions such as `pg_jsonschema`

This would provide much stronger guarantees for teams using JSON/JSONB as part of their relational modelling strategy.

This might tie into [this issue](https://github.com/drizzle-team/drizzle-orm/issues/5167)

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.