Skip to content

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 force-pushed the allow-fks-in-add-column branch from b257281 to bf8ca25 Compare September 5, 2023 12:26
@andrew-farries andrew-farries merged commit 4251184 into main Sep 6, 2023
@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.

2 participants