Skip to content

Commit 3a365ab

Browse files
qj0r9j0vc2claude
andcommitted
feat: skip migration for patch-only version upgrades
Patch version changes (e.g., v1.2.0 -> v1.2.3) now skip migration and only update the stored version. Migrations are only applied when major or minor versions change. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b450efa commit 3a365ab

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

internal/application/version/service.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,24 @@ func (s *Service) GetCurrentVersion(homeDir string) (*domainVersion.Version, err
5353
return v, nil
5454
}
5555

56+
// isPatchOnlyUpgrade checks if the version change is only a patch version bump.
57+
// Returns true if major and minor versions are the same, meaning only patch changed.
58+
// For example: 1.2.0 -> 1.2.3 returns true, but 1.2.0 -> 1.3.0 returns false.
59+
func isPatchOnlyUpgrade(current, target *version.Version) bool {
60+
currentSegs := current.Segments()
61+
targetSegs := target.Segments()
62+
63+
// Ensure we have at least major.minor for both versions
64+
if len(currentSegs) < 2 || len(targetSegs) < 2 {
65+
return false
66+
}
67+
68+
// Check if major and minor are the same
69+
return currentSegs[0] == targetSegs[0] && currentSegs[1] == targetSegs[1]
70+
}
71+
5672
// CheckAndMigrate checks if migration is needed and applies migrations.
73+
// Note: Patch-only upgrades (e.g., v1.2.0 -> v1.2.3) skip migration and only update the version.
5774
func (s *Service) CheckAndMigrate(ctx context.Context, homeDir string, target string) (*domainVersion.Version, error) {
5875
// Get current version
5976
current, err := s.GetCurrentVersion(homeDir)
@@ -83,6 +100,16 @@ func (s *Service) CheckAndMigrate(ctx context.Context, homeDir string, target st
83100
return nil, fmt.Errorf("downgrade from %s to %s is not supported", current.Current, target)
84101
}
85102

103+
// Skip migration for patch-only upgrades (e.g., v1.2.0 -> v1.2.3)
104+
if isPatchOnlyUpgrade(currentVer, targetVer) {
105+
s.logger.Debug("Patch-only upgrade %s -> %s, skipping migration", current.Current, target)
106+
current.Current = target
107+
if err := s.repository.Save(homeDir, current); err != nil {
108+
return nil, fmt.Errorf("failed to save version: %w", err)
109+
}
110+
return current, nil
111+
}
112+
86113
// Find migration path
87114
s.logger.Info("Migration needed: %s -> %s", current.Current, target)
88115
migrationPath, err := s.migrations.FindPath(current.Current, target)

0 commit comments

Comments
 (0)