Skip to content

Add support for CHECK constraints in create_table operation #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jan 16, 2025

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Jan 13, 2025

This PR adds a new type of constraints to create_table operation, named check. So from now, it is possible to configure table level check constraints.

Available settings:

  • check: required, check expression
  • no_inherit: disable constraint inheritance in child tables (default: false)

Example:

{
  "name": "50_create_table_with_table_constraint",
  "operations": [
    {
      "create_table": {
        "name": "phonebook",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "name",
            "type": "varchar(255)"
          }
        ],
        "constraints": [
          {
            "name": "name_must_be_present",
            "type": "check",
            "check": "length(name) > 0"
          }
        ]
      }
    }
  ]
}

Part of #580

@kvch kvch requested a review from andrew-farries January 13, 2025 15:48
@kvch kvch marked this pull request as ready for review January 13, 2025 15:49
@kvch kvch enabled auto-merge (squash) January 13, 2025 15:54
Copy link
Collaborator

@andrew-farries andrew-farries left a comment

Choose a reason for hiding this comment

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

Looks good.

I think we need some more JSON schema tests to cover validation, ie add some more invalid ones that fail the validation added on op_create_table.go:124

@kvch
Copy link
Contributor Author

kvch commented Jan 15, 2025

I added several new test cases for to the jsonschema package.

@kvch kvch requested a review from andrew-farries January 15, 2025 17:02
@kvch kvch merged commit e919085 into xataio:main Jan 16, 2025
28 checks passed
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.

2 participants