Skip to content

Fix redundant change stream SET FOR on FOR scope transitions#82

Merged
daichirata merged 1 commit intomasterfrom
fix/changestream-for-scope-regression
Feb 15, 2026
Merged

Fix redundant change stream SET FOR on FOR scope transitions#82
daichirata merged 1 commit intomasterfrom
fix/changestream-for-scope-regression

Conversation

@daichirata
Copy link
Copy Markdown
Owner

Summary

Fix an issue where redundant ALTER CHANGE STREAM ... SET FOR ... could be emitted during table drop processing, resulting in final DDL that does not match the target schema.

Background

When a change stream transitions from table scope to non-table scope (FOR ALL or no FOR), and one of watched tables is dropped:

  • from: FOR t1, t2
  • to: FOR ALL (or FOR NONE) + t1 dropped

the generator could output:

  1. ALTER ... SET FOR ALL (or DROP FOR ALL)
  2. ALTER ... SET FOR t2 (unexpected)

This made the final state incorrect (FOR t2 instead of target scope).

Changes

  • Updated change stream alter emission logic in internal/hammer/diff.go:
    • Emit intermediate SET FOR <remaining tables> only when the final target scope is FOR TABLES.
    • Avoid redundant intermediate alter when final scope is FOR ALL / FOR NONE.
  • Rewrote related comments in English.
  • Added regression tests in internal/hammer/diff_test.go:
    • FOR t1,t2 -> FOR ALL with t1 drop
    • FOR t1,t2 -> FOR NONE with t1 drop

Copy link
Copy Markdown
Contributor

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 a bug where redundant ALTER CHANGE STREAM ... SET FOR ... statements could be emitted during table drop processing when a change stream transitions from table scope (FOR t1, t2) to non-table scope (FOR ALL or FOR NONE). The generator was incorrectly emitting an intermediate SET FOR <remaining tables> followed by the final scope change, resulting in incorrect final DDL state.

Changes:

  • Fixed change stream alter emission logic to only emit intermediate SET FOR <remaining tables> when the final target scope is FOR TABLES
  • Updated Japanese comments to English for better maintainability
  • Added regression tests for multi-table to FOR ALL and multi-table to FOR NONE transitions with table drops

Reviewed changes

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

File Description
internal/hammer/diff.go Added condition to check target change stream type before emitting intermediate ALTER, preventing redundant statements when transitioning to non-table scopes; updated comments from Japanese to English
internal/hammer/diff_test.go Added two regression tests covering the bug scenarios: multi-table to FOR ALL with table drop, and multi-table to FOR NONE with table drop

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

@daichirata daichirata merged commit 59af808 into master Feb 15, 2026
18 checks passed
@daichirata daichirata deleted the fix/changestream-for-scope-regression branch February 15, 2026 12:21
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