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 indexes to columns created in the same migration #454

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

andrew-farries
Copy link
Collaborator

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

Allow the create_index operation to add an index to a column 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
        }
      }
    },
    {
      "create_index": {
        "name": "idx_player_rating",
        "table": "players",
        "columns": [
          "rating"
        ]
      }
    }
  ]
}

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 an index can be created on a column added earlier in the
same migration.
Ensure that the physical column names are used when creating indexes.
This allows an index to be created on a column added earlier in the same
migration.
@andrew-farries andrew-farries force-pushed the add-index-to-new-column branch from 18b5b7b to 86142d2 Compare November 7, 2024 07:32
@andrew-farries andrew-farries marked this pull request as ready for review November 7, 2024 07:34
@andrew-farries andrew-farries merged commit 1650210 into main Nov 7, 2024
27 checks passed
@andrew-farries andrew-farries deleted the add-index-to-new-column branch November 7, 2024 09:48
kvch pushed a commit to kvch/pgroll that referenced this pull request Nov 11, 2024
…#454)

Allow the `create_index` operation to add an index to a column 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
        }
      }
    },
    {
      "create_index": {
        "name": "idx_player_rating",
        "table": "players",
        "columns": [
          "rating"
        ]
      }
    }
  ]
}
```

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