Skip to content

Make payments payer→person/organization migration reversible#1564

Merged
maebeale merged 6 commits into
mainfrom
maebeale/payments-migration-reversible
Jun 6, 2026
Merged

Make payments payer→person/organization migration reversible#1564
maebeale merged 6 commits into
mainfrom
maebeale/payments-migration-reversible

Conversation

@maebeale

@maebeale maebeale commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

What is the goal of this PR and why is this important?

  • The ChangePaymentsPayerToPersonOrganization migration (from Add pay gem and payments/allocations/refunds #1487) used def change with unguarded remove_index / remove_column / add_reference.
  • That migration cannot be rolled back (add_reference/remove_column aren't trivially reversible from a change block) and fails on a partially-migrated database (e.g. if the index or column is already gone).
  • This blocks db:rollback / db:migrate:redo and recovery from a partial failure.

How did you approach the change?

  • Split the single change into explicit up / down methods.
  • Guarded every operation so it is idempotent and recovers from partial state:
    • remove_index / remove_column / remove_reference use if_exists: true
    • add_reference / add_column are guarded with column_exists? / unless
    • add_index uses if_not_exists: true
  • down restores the original payer_id column and index_payments_on_payer index.
  • No schema-outcome change for a clean forward migration — this only makes rollback safe.

Anything else to add?

  • Split out from the event overview dashboard branch so the migration fix can land independently.

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>
Copilot AI review requested due to automatic review settings June 6, 2026 00:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 change with explicit def up / def down to make rollback possible.
  • Added idempotency guards (if_exists, if_not_exists, column_exists?) around schema changes.
  • Implemented a rollback path that removes person/organization references and restores payer_id plus an index.

Comment thread db/migrate/20260530000000_change_payments_payer_to_person_organization.rb Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 6, 2026 01:20
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@maebeale maebeale marked this pull request as ready for review June 6, 2026 01:20
@maebeale maebeale requested a review from jmilljr24 June 6, 2026 01:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

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>
Copilot AI review requested due to automatic review settings June 6, 2026 01:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread Gemfile Outdated
gem "aws-sdk-s3"

gem "puma", "~> 6.0" # Add Puma as the web server
gem "puma", "~> 7.2" # Add Puma as the web server
Copilot AI review requested due to automatic review settings June 6, 2026 02:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@maebeale maebeale merged commit 4839251 into main Jun 6, 2026
5 of 6 checks passed
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