Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@andrew-farries
Copy link
Collaborator

Change the create_index operation to take the columns on which the index should be defined as an list rather than a map.

This ensures that the ordering of the columns in in the index is fixed to the same order as they appear in the migration file.

old format

# foo
operations:
  - create_index:
      name: some-index
      table: tickets
      columns:
        column1: {}
        column2: {}

new format

operations:
- create_index:
    name: some-index
    table: tickets
    columns:
    - column: column1
      # options
    - column: column2
      # options

The changes in this PR are taken from reve-ai#5 🙏

⚠️ This is a breaking change to the migration format ⚠️

We also modify the pgroll update command in this PR so that operations in the old format can be migrated to the new format (although for multi-column indexes the user will still have to ensure that the column order in the updated migration is what they expected).

Fixes #1001

Add an updater function to convert `create_index` operations from using
a map format for columns to an array format.
@github-actions github-actions bot temporarily deployed to Docs Preview December 18, 2025 10:11 Inactive
@github-actions github-actions bot temporarily deployed to Docs Preview December 18, 2025 10:38 Inactive
@github-actions
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgroll/cmd 0.00% (ø)
github.com/xataio/pgroll/pkg/migrations 77.59% (+0.07%) 👍
github.com/xataio/pgroll/pkg/sql2pgroll 88.98% (+0.02%) 👍
github.com/xataio/pgroll/pkg/sql2pgroll/expect 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgroll/cmd/update.go 0.00% (ø) 39 0 39
github.com/xataio/pgroll/pkg/migrations/dbactions.go 89.62% (ø) 212 190 22
github.com/xataio/pgroll/pkg/migrations/op_create_index.go 67.44% (-0.06%) 43 (+3) 29 (+2) 14 (+1) 👎
github.com/xataio/pgroll/pkg/migrations/pterm_create.go 0.00% (ø) 168 0 168
github.com/xataio/pgroll/pkg/migrations/types.go 0.00% (ø) 0 0 0
github.com/xataio/pgroll/pkg/migrations/updater.go 86.67% (+0.46%) 45 (+16) 39 (+14) 6 (+2) 👍
github.com/xataio/pgroll/pkg/sql2pgroll/create_index.go 87.30% (+0.20%) 63 (+1) 55 (+1) 8 👍
github.com/xataio/pgroll/pkg/sql2pgroll/expect/create_index.go 0.00% (ø) 5 0 5

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgroll/pkg/migrations/op_create_index_test.go
  • github.com/xataio/pgroll/pkg/migrations/op_drop_index_test.go
  • github.com/xataio/pgroll/pkg/migrations/updater_test.go
  • github.com/xataio/pgroll/pkg/sql2pgroll/convert_test.go

@andrew-farries andrew-farries marked this pull request as ready for review December 18, 2025 15:18
@andrew-farries andrew-farries merged commit aee9741 into main Dec 18, 2025
34 checks passed
@andrew-farries andrew-farries deleted the fix-create-index-operation branch December 18, 2025 15:23
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.

OpCreateIndex columns are not ordered

3 participants