Skip to content

fix: progressive migrations#919

Open
ferhatelmas wants to merge 1 commit intomasterfrom
ferhat/progressive-migrations
Open

fix: progressive migrations#919
ferhatelmas wants to merge 1 commit intomasterfrom
ferhat/progressive-migrations

Conversation

@ferhatelmas
Copy link
Member

@ferhatelmas ferhatelmas commented Mar 18, 2026

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Progressive migration can get stuck because emitting flag is not reverting back on error.

What is the new behavior?

Ensure flag is reverted on errors.
Keep tasks in memory queue until enqueue.
Add regression coverage.

@ferhatelmas ferhatelmas requested a review from a team as a code owner March 18, 2026 18:16
Copilot AI review requested due to automatic review settings March 18, 2026 18:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes progressive migration scheduling so it doesn’t get stuck when job emission fails, by ensuring the in-memory queue and emittingJobs state are handled safely across errors and retries.

Changes:

  • Updates ProgressiveMigrations.createJobs() to keep tenants queued on failures, only removing tenants after successful preparation/emission, and always resetting emittingJobs via finally.
  • Adds regression tests covering batchSend failures, in-flight batching behavior, duplicate tenant adds, and per-tenant job preparation failures.

Reviewed changes

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

File Description
src/internal/database/migrations/progressive.ts Reworks batching/removal semantics to preserve queued tenants on failures and reset emittingJobs reliably.
src/test/progressive-migrations.test.ts Adds focused regression coverage for failure and in-flight queue behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a progressive migration scheduling bug where the in-memory “emitting” flag could remain stuck after failures, preventing further job emission. The changes adjust the progressive job-emission flow to keep tenants queued until emission succeeds and add regression tests around both progressive batching and the migration worker event handler.

Changes:

  • Serialize/guard progressive job creation via an in-flight promise and ensure emittingJobs is always reset (even on errors).
  • Keep tenants in the in-memory queue until migration jobs are successfully emitted; retain tenants when job preparation/emission fails.
  • Add regression coverage for progressive batching behavior and RunMigrationsOnTenants.handle outcomes.

Reviewed changes

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

File Description
src/internal/database/migrations/progressive.ts Refactors progressive batching to be failure-safe (no lost tenants) and to reset the emitting flag reliably via finally.
src/test/progressive-migrations.test.ts Adds regression tests for “keep queued on failure”, “in-flight batch behavior”, and “drain serialization”.
src/test/run-migrations-event.test.ts Adds unit tests for the migrations queue worker handler covering success, short-circuit, lock timeout, and retry/final-failure behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes progressive tenant migrations getting stuck by ensuring the “emitting” state is always reset and by keeping tenants in the in-memory queue until jobs are successfully emitted.

Changes:

  • Refactors ProgressiveMigrations job emission to serialize in-flight emits and only dequeue tenants after successful batch emission.
  • Adds regression tests for progressive migration queueing/emitting behavior.
  • Adds coverage for RunMigrationsOnTenants.handle success/short-circuit/lock-timeout/retry behavior.

Reviewed changes

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

File Description
src/internal/database/migrations/progressive.ts Introduces in-flight serialization and delayed dequeuing for progressive migration job emission.
src/test/progressive-migrations.test.ts Adds regression tests for queue retention, in-flight behavior, and preparation failures.
src/test/run-migrations-event.test.ts Adds tests for the migration job handler’s success and error paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@ferhatelmas ferhatelmas force-pushed the ferhat/progressive-migrations branch 2 times, most recently from 364b5eb to a94c29e Compare March 18, 2026 19:06
@ferhatelmas ferhatelmas requested a review from Copilot March 18, 2026 19:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes progressive tenant migrations potentially getting stuck by ensuring the “emitting” state is always reset after job creation attempts and by retaining tenants in the in-memory queue until enqueue succeeds, with added regression tests around these behaviors.

Changes:

  • Serialize progressive job creation via an in-flight promise and reset emittingJobs in a finally path.
  • Keep tenants queued until batchSend succeeds; log and retain tenants when job preparation fails.
  • Add regression tests for ProgressiveMigrations behavior and RunMigrationsOnTenants.handle retry/failure paths.

Reviewed changes

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

File Description
src/internal/database/migrations/progressive.ts Reworks progressive job creation to be in-flight/serialized and to retain tenants until successful enqueue.
src/test/progressive-migrations.test.ts Adds regression coverage for queue retention, emitting flag reset, and in-flight serialization edge cases.
src/test/run-migrations-event.test.ts Adds coverage for migration event handling across success, lock-timeout, and retryable failure scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@ferhatelmas ferhatelmas force-pushed the ferhat/progressive-migrations branch from a94c29e to 3f2a74f Compare March 18, 2026 21:15
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
@ferhatelmas ferhatelmas force-pushed the ferhat/progressive-migrations branch from 3f2a74f to 3abe0f6 Compare March 18, 2026 21:18
@ferhatelmas ferhatelmas requested a review from Copilot March 18, 2026 21:18
Copy link

Copilot AI left a comment

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 fixes progressive migration scheduling reliability by ensuring the “emitting” state is always reset on failure, and by keeping tenants in the in-memory queue until enqueue succeeds, with added regression tests to prevent the scheduler from getting stuck.

Changes:

  • Serialize/guard progressive migration job creation with an in-flight promise and always reset emittingJobs via finally.
  • Keep tenants queued until successful enqueue; move prep-failed tenants to the back for retry rather than dropping them.
  • Add regression tests for ProgressiveMigrations behavior and RunMigrationsOnTenants.handle outcomes.

Reviewed changes

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

File Description
src/internal/database/migrations/progressive.ts Reworks job creation to be serialized and failure-safe; keeps tenant queue intact until enqueue succeeds.
src/test/progressive-migrations.test.ts Adds regression coverage for queue retention, in-flight serialization, and failure logging/ordering.
src/test/run-migrations-event.test.ts Adds coverage for migration event handler success, short-circuiting, lock-timeout handling, and retry failure states.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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.

3 participants