Skip to content
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

Add support for creating CHECK constraints with create_constraint #464

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Nov 14, 2024

This PR introduces a new constraint type to create_constraint operation called check. Now it is possible to create check constraints on multiple columns.

Example

{
  "name": "45_add_table_check_constraint",
  "operations": [
    {
      "create_constraint": {
        "type": "check",
        "table": "tickets",
        "name": "check_zip_name",
        "columns": [
          "sellers_name",
          "sellers_zip"
        ],
        "check": "sellers_name ~ 'Alice' AND sellers_zip IS NOT NULL",
        "up": {
          "sellers_name": "Alice",
          "sellers_zip": "(SELECT CASE WHEN sellers_zip IS NOT NULL THEN sellers_zip ELSE '00000' END)"
        },
        "down": {
          "sellers_name": "sellers_name",
          "sellers_zip": "sellers_zip"
        }
      }
    }
  ]
}

@kvch
Copy link
Contributor Author

kvch commented Nov 14, 2024

I've found a bug in column duplication for unique indexes with multiple columns, so the example is failing. I am adding a fix in a separate PR.

@kvch
Copy link
Contributor Author

kvch commented Nov 14, 2024

Bugfix: #466

@kvch
Copy link
Contributor Author

kvch commented Nov 14, 2024

It is highly likely we need to adjust the check constraint migrations as well. I will address those issues in a follow-up PR.

examples/45_add_table_check_constraint.json Outdated Show resolved Hide resolved
pkg/migrations/op_create_constraint_test.go Outdated Show resolved Hide resolved
pkg/migrations/op_create_constraint_test.go Show resolved Hide resolved
pkg/migrations/op_create_constraint_test.go Outdated Show resolved Hide resolved
pkg/migrations/op_create_constraint_test.go Outdated Show resolved Hide resolved
pkg/migrations/op_create_constraint_test.go Show resolved Hide resolved
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