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

Support creating foreign key constraints with the add column operation #80

Merged
merged 3 commits into from
Sep 6, 2023

Conversation

andrew-farries
Copy link
Collaborator

Allow the add column operation to create foreign key columns.

An example of such an operation is:

{
  "name": "17_add_rating_column",
  "operations": [
    {
      "add_column": {
        "table": "orders",
        "column": {
          "name": "user_id",
          "type": "integer",
          "references": {
            "table": "users",
            "column": "id",
          }
        }
      }
    }
  ]
}

Most of the work to support the operation is in #79.

  • The constraint is added on Start (named according to the temporary name of the new column).
  • The entire new column, including the foreign key constraint, is removed on Rollback.
  • The constraint is renamed to use the final name of the new column on Complete.

Test cases are included for both nullable and non-nullable FKs.

Base automatically changed from allow-fks-in-create-table to main September 5, 2023 12:25
@andrew-farries andrew-farries merged commit 4251184 into main Sep 6, 2023
3 checks passed
@andrew-farries andrew-farries deleted the allow-fks-in-add-column branch September 6, 2023 04:43
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.

None yet

2 participants