Skip to content

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

@rieger-jared

Description

@rieger-jared

Feature hasn't been suggested before.

  • 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 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions