Make payments payer→person/organization migration reversible#1564
Merged
Conversation
The original migration used `def change` with unguarded `remove_index`, `remove_column`, and `add_reference`, so it could not be rolled back and would fail on a partially-migrated database. Split into explicit up/down with `if_exists`/`if_not_exists` and `column_exists?` guards so rollbacks are idempotent and recover from partial failures. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the ChangePaymentsPayerToPersonOrganization migration to be safely reversible and more resilient to partially-migrated database states by replacing an unsafe change method with explicit up/down methods.
Changes:
- Replaced
def changewith explicitdef up/def downto make rollback possible. - Added idempotency guards (
if_exists,if_not_exists,column_exists?) around schema changes. - Implemented a rollback path that removes
person/organizationreferences and restorespayer_idplus an index.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Puma 6.6.1 is vulnerable to CVE-2026-47736 and CVE-2026-47737 (PROXY protocol v1 remote memory exhaustion and repeated-header acceptance), both rated High. The advisory's fix is `~> 7.2.1` or `>= 8.0.2`, so bump to the 7.2 line, which keeps us on a single major upgrade. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| gem "aws-sdk-s3" | ||
|
|
||
| gem "puma", "~> 6.0" # Add Puma as the web server | ||
| gem "puma", "~> 7.2" # Add Puma as the web server |
This reverts commit 476d9b2.
…ration-reversible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the goal of this PR and why is this important?
ChangePaymentsPayerToPersonOrganizationmigration (from Add pay gem and payments/allocations/refunds #1487) useddef changewith unguardedremove_index/remove_column/add_reference.add_reference/remove_columnaren't trivially reversible from achangeblock) and fails on a partially-migrated database (e.g. if the index or column is already gone).db:rollback/db:migrate:redoand recovery from a partial failure.How did you approach the change?
changeinto explicitup/downmethods.remove_index/remove_column/remove_referenceuseif_exists: trueadd_reference/add_columnare guarded withcolumn_exists?/unlessadd_indexusesif_not_exists: truedownrestores the originalpayer_idcolumn andindex_payments_on_payerindex.Anything else to add?