Feature 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 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
Feature 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 It would be fantastic if Drizzle could optionally leverage this to emit database-level JSON validation constraints for supported databases.
Potential flow:
MySQL would enforce this via
JSON_SCHEMA_VALIDand PostgreSQL via extensions such aspg_jsonschemaThis would provide much stronger guarantees for teams using JSON/JSONB as part of their relational modelling strategy.
This might tie into this issue