Skip to content

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Jul 2, 2025

This PR makes column duplication idempotent. Previously, if the same column was altered in multiple operations in the same migration was not working. The modified column could not be duplicated in the second operation because the ALTER TABLE statement has failed. I added IF NOT EXISTS to make the column creation idempotent. Now the column is duplicated once, and other changes are added on top of it like setting not null constraints, changing default values, etc.

The only edge case this PR does not address is when the column type is changed in a later operation. This limitation can be worked around by changing the type first in an alter_column operation and then adding other changes to the migration. I do opted for this trade-off because it would increase the complexity of the duplicator but not much of an upside.

This is working:

operations:
 - alter_column:
    name: mycol
    type: text
 - alter_column:
    name: mycol
    comment: nocomment

This is not supported:

operations:
 - alter_column:
    name: mycol
    comment: nocomment
 - alter_column:
    name: mycol
    type: text

@github-actions github-actions bot temporarily deployed to Docs Preview July 2, 2025 14:29 Inactive
@kvch kvch changed the base branch from main to feature-dbaction-coordinator July 4, 2025 13:40
@kvch kvch force-pushed the fix-duplicate-backfilled-column branch from 2e2786b to e4632d4 Compare July 4, 2025 13:41
@github-actions github-actions bot temporarily deployed to Docs Preview July 4, 2025 13:42 Inactive
@kvch kvch force-pushed the fix-duplicate-backfilled-column branch from e4632d4 to 9bd2749 Compare July 4, 2025 13:44
@github-actions github-actions bot temporarily deployed to Docs Preview July 4, 2025 13:44 Inactive
Base automatically changed from feature-dbaction-coordinator to main July 24, 2025 16:25
@kvch kvch force-pushed the fix-duplicate-backfilled-column branch from 9bd2749 to 0162b2b Compare July 30, 2025 10:02
@github-actions github-actions bot temporarily deployed to Docs Preview July 30, 2025 10:02 Inactive
@kvch kvch force-pushed the fix-duplicate-backfilled-column branch from 0162b2b to 0038ea3 Compare July 30, 2025 10:07
@github-actions github-actions bot temporarily deployed to Docs Preview July 30, 2025 10:07 Inactive
@github-actions github-actions bot temporarily deployed to Docs Preview August 6, 2025 12:03 Inactive
@kvch kvch marked this pull request as ready for review August 7, 2025 17:17
@kvch kvch requested a review from andrew-farries August 7, 2025 17:17
@@ -33,7 +33,7 @@ func NewCoordinator(actions []DBAction) *Coordinator {
}
}

// Execute runs all actions in the order they were added to the coordinator.
// Execute runs all actions in the orderedActions they were added to the coordinator.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need this change I think

@github-actions github-actions bot temporarily deployed to Docs Preview August 12, 2025 10:53 Inactive
@kvch kvch enabled auto-merge (squash) August 12, 2025 10:53
@kvch kvch merged commit c9d2566 into main Aug 12, 2025
29 checks passed
@kvch kvch deleted the fix-duplicate-backfilled-column branch August 12, 2025 10:55
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgroll/pkg/backfill 4.84% (ø)
github.com/xataio/pgroll/pkg/migrations 77.41% (+0.05%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgroll/pkg/backfill/backfill.go 0.00% (ø) 87 0 87
github.com/xataio/pgroll/pkg/migrations/duplicate.go 94.03% (-0.50%) 134 (+6) 126 (+5) 8 (+1) 👎
github.com/xataio/pgroll/pkg/migrations/op_alter_column.go 90.60% (+0.25%) 117 (+3) 106 (+3) 11 👍

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_alter_column_test.go

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