Skip to content

Commit 9c5382d

Browse files
committed
fix(migrator): add missing helper functions for v0.4.1
- Add isAlreadyExistsError() function for consistent error detection - Add isAutoIncrementField() method for proper field identification - Improve migration robustness and DuckDB compatibility - Update CHANGELOG.md for v0.4.1 patch release These helper functions enhance migration reliability by providing better error handling and auto-increment field detection.
1 parent 4c60e17 commit 9c5382d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.4.1] - 2025-08-20
11+
12+
### 🔧 Fixed
13+
14+
- **Migrator Helper Functions**: Added missing helper functions for improved migration reliability
15+
- `isAlreadyExistsError()`: Checks if an error indicates object already exists (handles "already exists" and "duplicate" error patterns)
16+
- `isAutoIncrementField()`: Identifies auto-increment fields for proper sequence handling
17+
- **Code Organization**: Better separation of concerns in migrator functionality
18+
19+
### 🛠️ Technical Details
20+
21+
The helper functions improve migration robustness by:
22+
23+
- **Error Handling**: Consistent detection of duplicate object creation attempts
24+
- **Auto-increment Detection**: Proper identification of fields requiring sequence-based auto-increment behavior
25+
- **DuckDB Compatibility**: Enhanced support for DuckDB-specific migration patterns
26+
27+
These changes maintain full backward compatibility while improving internal migration logic.
28+
1029
## [0.4.0] - 2025-08-14
1130

1231
### 🚀 Comprehensive Extension Management & Test Coverage Revolution

migrator.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,26 @@ const (
1616
sqlTypeInteger = "INTEGER"
1717
)
1818

19+
// isAlreadyExistsError checks if an error indicates that an object already exists
20+
func isAlreadyExistsError(err error) bool {
21+
if err == nil {
22+
return false
23+
}
24+
errMsg := strings.ToLower(err.Error())
25+
return strings.Contains(errMsg, "already exists") ||
26+
strings.Contains(errMsg, "duplicate")
27+
}
28+
1929
// Migrator implements gorm.Migrator interface for DuckDB database.
2030
type Migrator struct {
2131
migrator.Migrator
2232
}
2333

34+
// isAutoIncrementField checks if a field is an auto-increment field
35+
func (m Migrator) isAutoIncrementField(field *schema.Field) bool {
36+
return field.AutoIncrement || (!field.HasDefaultValue && field.DataType == schema.Uint)
37+
}
38+
2439
// CurrentDatabase returns the current database name.
2540
func (m Migrator) CurrentDatabase() (name string) {
2641
_ = m.DB.Raw("SELECT current_database()").Row().Scan(&name)

0 commit comments

Comments
 (0)