Skip to content

Conversation

@louisdussarps
Copy link
Contributor

@louisdussarps louisdussarps commented Dec 5, 2025

Change description

This PR enables the ability to define validation at the row level of a table through SQL check constraint.
To do this :

  • collection have a new field "check_filter" which is a json with the directus filter syntax : {value : {_gt : 10}}...
  • when "check_filter" is modified for a collection, a check constraint is added to the collection table :
    - to enable comparison between fields of the same table, the filter syntax is extended : {date_start : {_lt : $FIELD(date_end)
  • In the frontend app, a section "check constraint" is added at the bottom of the page : it makes it possible to build the directus filter visually.
    - to enable comparison between fields of the same table, the filter ux is extended : on the right-hand size of an operator, it's possible to select one of collection's field
image
> \d test

                            Table "public.test"
   Column   |            Type             | Collation | Nullable | Default 
------------+-----------------------------+-----------+----------+---------
 id         | uuid                        |           | not null | 
 date_start | timestamp without time zone |           |          | 
 date_end   | timestamp without time zone |           |          | 
 score      | integer                     |           |          | 
Indexes:
    "test_pkey" PRIMARY KEY, btree (id)
Check constraints:
    "directus_constraint" CHECK (score >= 0 AND score <= 10 AND date_start < date_end)

Important note : currently, the constraints are available only for postgres
When knex make dropConstraintIfExists available (cf this issue), it will be possible to support all vendors

Type of change

  • Bug fix (fixes an issue)
  • New feature (adds functionality)

Related issues

Checklists

Development

  • Lint rules pass locally
  • Application changes have been tested thoroughly
  • Automated tests covering modified code pass

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

Code review

  • Pull request has a descriptive title and context useful to a reviewer. Screenshots or screencasts are attached as necessary
  • reviewers assigned
  • Pull request linked to task tracker where applicable

@louisdussarps louisdussarps marked this pull request as draft December 5, 2025 14:35
@louisdussarps louisdussarps marked this pull request as ready for review December 6, 2025 10:02
Copy link
Collaborator

@sofiachakir sofiachakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

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.

3 participants