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 foreign key constraints using create_constraint #471

Merged

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Nov 19, 2024

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

Examples

Foreign key

{
  "name": "44_add_foreign_key_table_reference_constraint",
  "operations": [
    {
      "create_constraint": {
        "type": "foreign_key",
        "table": "tickets",
        "name": "fk_sellers",
        "columns": [
          "sellers_name",
          "sellers_zip"
        ],
        "references": {
          "table": "sellers",
          "columns": [
            "name",
            "zip"
          ],
          "on_delete": "CASCADE"
        },
        "up": {
          "sellers_name": "sellers_name",
          "sellers_zip": "sellers_zip"
        },
        "down": {
          "sellers_name": "sellers_name",
          "sellers_zip": "sellers_zip"
        }
      }
    }
  ]
}

Closes #81

@andrew-farries
Copy link
Collaborator

Multi-column FKs currently can't be duplicated due to #475.

Once that is resolved we can implement duplication of multi-column FKs on this PR, which is the last addition that needs to happen here before merge.

@andrew-farries andrew-farries force-pushed the feature-create-constraint-op-iii-foreign branch 2 times, most recently from 72b7402 to d69e015 Compare November 22, 2024 08:35
kvch and others added 5 commits November 22, 2024 08:41
Set a default so that the generated type is `string` not `*string`.
Ensure that foreign key constraints, including multi-column constraints,
are duplicated correctly.
@andrew-farries andrew-farries force-pushed the feature-create-constraint-op-iii-foreign branch from d69e015 to 9fe8d9b Compare November 22, 2024 08:42
@andrew-farries andrew-farries merged commit a9b2048 into xataio:main Nov 22, 2024
27 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.

Support multi-column foreign keys
2 participants