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 an index to a table created in the same migration #451

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

andrew-farries
Copy link
Collaborator

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

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 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.
Ensure that an index can be added to a table that was created by an
operation earlier in the same migration.
@andrew-farries andrew-farries marked this pull request as ready for review November 6, 2024 11:46
@kvch
Copy link
Contributor

kvch commented Nov 6, 2024

This can be closed now: #203

@andrew-farries
Copy link
Collaborator Author

This can be closed now: #203

I think we can't close it yet. The migration in the PR description still requires --skip-validation to work. Validating the migration is something still to be done.

@andrew-farries andrew-farries merged commit c677bbe into main Nov 6, 2024
27 checks passed
@andrew-farries andrew-farries deleted the add-index-to-table-in-same-migration branch November 6, 2024 12:36
kvch pushed a commit to kvch/pgroll that referenced this pull request Nov 11, 2024
…o#451)

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

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