Skip to content

perf: reduce schema sync operations from 3 to 2 during migration #17101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025

Conversation

d-bytebase
Copy link
Collaborator

Summary

  • Optimized schema migration process to reduce sync operations from 3 to 2
  • Combined post-migration history sync with metadata update into a single operation
  • Removed ~78 lines of redundant sync code from executor implementations

Problem

During each schema migration, we were performing 3 separate database sync operations:

  1. Pre-migration: Creates history snapshot
  2. Post-migration: Creates history snapshot
  3. Final: Updates live metadata

This was inefficient as operations 2 and 3 could be combined.

Solution

Refactored the sync process to combine the post-migration history creation with metadata update:

  1. Pre-migration: Creates history snapshot
  2. Post-migration: Creates history AND updates metadata in one operation

Changes Made

  • syncer.go: Renamed internal implementation to doSyncDatabaseSchema() to avoid naming conflicts
  • executor.go: Updated endMigration() to always perform schema sync (with or without history)
  • All executor files: Removed redundant sync code since sync is now always done in endMigration()

Performance Impact

  • Reduces database operations by 33% during migrations
  • Maintains all functionality for audit trails, rollback capabilities, and metadata accuracy
  • Cleaner codebase with ~78 lines of redundant code removed

Test Plan

  • Verify schema migrations work correctly
  • Confirm both pre and post migration history are created
  • Validate metadata is properly updated after migration
  • Test with different migration types (DDL, SDL, Ghost, Data)

🤖 Generated with Claude Code

Previously, we performed 3 separate schema sync operations during each migration:
1. Pre-migration: SyncDatabaseSchemaToHistory() - creates history snapshot
2. Post-migration: SyncDatabaseSchemaToHistory() - creates history snapshot
3. Final: SyncDatabaseSchema() - updates live metadata

This commit optimizes the process to only 2 sync operations:
1. Pre-migration: SyncDatabaseSchemaToHistory() - creates history snapshot
2. Post-migration: Combined sync that creates history AND updates metadata

Changes:
- Refactored syncer.go to expose doSyncDatabaseSchema() as the core implementation
- Updated endMigration() to always perform schema sync (with or without history)
- Removed redundant sync calls from all executor implementations
- Cleaned up unused imports

This reduces database operations by 33% during migrations while maintaining
all functionality for audit trails, rollback capabilities, and metadata accuracy.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@d-bytebase d-bytebase requested a review from a team as a code owner August 7, 2025 08:26
@cla-bot cla-bot bot added the cla-signed label Aug 7, 2025
@d-bytebase d-bytebase enabled auto-merge (squash) August 7, 2025 08:32
@d-bytebase d-bytebase merged commit 1cc3504 into main Aug 7, 2025
11 checks passed
@d-bytebase d-bytebase deleted the reduce-schema-sync-operations branch August 7, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants