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

Update schema during add column validation #457

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

andrew-farries
Copy link
Collaborator

Update the schema during add_column operation validation so that validation of subsequent operations in the same migration can see the new column.

This means that migrations that add a new column and then perform some other operation, like adding an index, on that column can be validated because the new column is visible to the create_index operation during it's validation phase.

This means that the following migration is now able to validate:

{
  "name": "43_multiple_ops",
  "operations": [
    {
      "add_column": {
        "table": "players",
        "column": {
          "name": "rating",
          "type": "integer",
          "comment": "hello world",
          "check": {
            "name": "rating_check",
            "constraint": "rating > 0 AND rating < 100"
          },
          "nullable": false
        }
      }
    },
    {
      "create_index": {
        "name": "idx_player_rating",
        "table": "players",
        "columns": [
          "rating"
        ]
      }
    }
  ]
}

Previously, the new column would not have been visible to the create_index operation and its validation would have failed.

This PR does for the add_column operation what #455 did for the create_table operation.

Part of #239

@andrew-farries andrew-farries marked this pull request as ready for review November 7, 2024 15:42
Base automatically changed from update-schema-in-create-table-validation to main November 8, 2024 14:26
Add the new column to the schema during validation so that subsequent
operations in the same migration can assume its existence during their
own validation step.
This commit enforces the validation in the test that was previously
skipped.

This is possible now that the validation of the add column
operation updates the schema with the new column so that the validation
of the subsequent create index operation can be performed.
@andrew-farries andrew-farries force-pushed the update-schema-in-add-column-validation branch from 5cf8732 to e1608c3 Compare November 8, 2024 14:26
@andrew-farries andrew-farries merged commit 416fb7a into main Nov 8, 2024
27 checks passed
@andrew-farries andrew-farries deleted the update-schema-in-add-column-validation branch November 8, 2024 14:31
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