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

Allow adding a column to a table created in the same migration #449

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Nov 6, 2024

Allow the add_column operation to add a column to a table that was created by an operation earlier in the same migration.

The following migration would previously have failed to start:

{
  "name": "43_multiple_ops",
  "operations": [
    {
      "create_table": {
        "name": "players",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "name",
            "type": "varchar(255)",
            "check": {
              "name": "name_length_check",
              "constraint": "length(name) > 2"
            }
          }
        ]
      }
    },
    {
      "add_column": {
        "table": "players",
        "column": {
          "name": "rating",
          "type": "integer",
          "comment": "hello world",
          "check": {
            "name": "rating_check",
            "constraint": "rating > 0 AND rating < 100"
          },
          "nullable": false
        }
      }
    }
  ]
}

As of this PR, the migration can be started.

The above migration does not validate yet, but it can be started successfully with the --skip-validation flag to the start command.

Part of #239

Ensure that the add column operation works correctly when the column is
added to a table that was created in the same migration.
Ensure that the table is referred to by the its name in the virtual
schema - this is aware of the temporary name that is used for the
table in the migration.
@andrew-farries andrew-farries merged commit 171f5a2 into main Nov 6, 2024
27 checks passed
@andrew-farries andrew-farries deleted the add-column-to-table-in-same-migration branch November 6, 2024 11:10
kvch pushed a commit to kvch/pgroll that referenced this pull request Nov 11, 2024
…o#449)

Allow the `add_column` operation to add a column to a table that was
created by an operation earlier in the same migration.

The following migration would previously have failed to start:

```json
{
  "name": "43_multiple_ops",
  "operations": [
    {
      "create_table": {
        "name": "players",
        "columns": [
          {
            "name": "id",
            "type": "serial",
            "pk": true
          },
          {
            "name": "name",
            "type": "varchar(255)",
            "check": {
              "name": "name_length_check",
              "constraint": "length(name) > 2"
            }
          }
        ]
      }
    },
    {
      "add_column": {
        "table": "players",
        "column": {
          "name": "rating",
          "type": "integer",
          "comment": "hello world",
          "check": {
            "name": "rating_check",
            "constraint": "rating > 0 AND rating < 100"
          },
          "nullable": false
        }
      }
    }
  ]
}
```

As of this PR, the migration can be started.

The above migration does not validate yet, but it can be started
successfully with the `--skip-validation` flag to the `start` command.

Part of xataio#239
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