Conversation
Add MigrationStatus (New|Executed|Modified). Optimize checksum-first query; avoid duplicate records for renamed scripts. Normalize tags and add tests. Fix DTC test.
Reviewer's GuideNormalizes struct Sequence diagram for binding with normalized db tagssequenceDiagram
actor Test as TestCode
participant DB as SQLiteDB
participant Rows as SQLRows
participant BinderFactory as binder_struct_go
participant SB as structBinder
participant User as UserStruct
Test->>DB: Execute query SELECT * FROM users
DB-->>Test: Rows handle
Test->>BinderFactory: newStructBinder(UserType, UserValue)
BinderFactory-->>SB: structBinder instance
loop For each column in rows metadata
SB->>SB: read db tag or field name
SB->>SB: normalizedTag = toLower(removeUnderscores(tagName))
SB->>SB: fieldIndexes[normalizedTag] = fieldIndex
SB->>SB: append fieldColumnNames with original tagName
end
loop For each row in Rows
Test->>Rows: Scan next row
Rows-->>Test: columnValues, columnNames
Test->>SB: bindRow(columnValues, columnNames)
SB->>SB: normalize each columnName (lowercase, remove underscores)
SB->>SB: lookup fieldIndex = fieldIndexes[normalizedColumnName]
SB->>User: set struct field using fieldIndex and value
end
SB-->>Test: bound User instances
Class diagram for updated struct binder tag normalizationclassDiagram
class Binder {
<<interface>>
}
class structBinder {
map~string,int~ fieldIndexes
string[] fieldColumnNames
reflectType type
reflectValue value
newRowBinder() RowBinder
bindRow(scanner Scanner) error
}
class RowBinder {
<<interface>>
}
class Scanner {
<<interface>>
}
Binder <|.. structBinder
class binder_struct_go {
+newStructBinder(t reflectType, v reflectValue) Binder
-normalizeTagName(tagName string) string
}
binder_struct_go ..> structBinder : creates
binder_struct_go ..> Binder
note for structBinder "fieldIndexes now uses normalized db tag keys (lowercased, underscores removed) while fieldColumnNames preserves original tag names"
%% Representation of the updated logic inside newStructBinder
structBinder o-- map_string_int_fieldIndexes : uses
structBinder o-- string_array_fieldColumnNames : uses
class map_string_int_fieldIndexes {
+set(key string, index int)
+get(key string) int
}
class string_array_fieldColumnNames {
+append(name string)
+get(i int) string
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Here's the code health analysis summary for commits Analysis Summary
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The tag normalization logic (
strings.ToLower(strings.ReplaceAll(tagName, "_", ""))) should ideally be shared with whatever normalization is used for column names to avoid drift if one side changes in the future. - If
dbtags can include options (e.g.,db:"first_name,omitempty"), the current normalization will treat the whole tag string as the name; consider splitting on,before normalizing to avoid unexpected behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The tag normalization logic (`strings.ToLower(strings.ReplaceAll(tagName, "_", ""))`) should ideally be shared with whatever normalization is used for column names to avoid drift if one side changes in the future.
- If `db` tags can include options (e.g., `db:"first_name,omitempty"`), the current normalization will treat the whole tag string as the name; consider splitting on `,` before normalizing to avoid unexpected behavior.
## Individual Comments
### Comment 1
<location> `binder_struct.go:29-30` </location>
<code_context>
if tagName != "" {
- sb.fieldIndexes[tagName] = i
+ // Normalize tag name to match column name processing: remove underscores and lowercase
+ normalizedTag := strings.ToLower(strings.ReplaceAll(tagName, "_", ""))
+ sb.fieldIndexes[normalizedTag] = i
sb.fieldColumnNames = append(sb.fieldColumnNames, tagName)
continue
</code_context>
<issue_to_address>
**issue (bug_risk):** Normalized tag keys may collide, silently overwriting earlier fields.
Because normalization removes underscores and lowercases, tags like `user_id` and `UserId` will both map to the same `normalizedTag`, so the later field silently overwrites the earlier one in `sb.fieldIndexes`. If that’s not intended, consider detecting collisions and either failing, logging, or skipping the overwrite so the behavior is explicit instead of silent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #55 +/- ##
==========================================
+ Coverage 77.58% 77.75% +0.16%
==========================================
Files 46 46
Lines 1896 1897 +1
==========================================
+ Hits 1471 1475 +4
+ Misses 304 300 -4
- Partials 121 122 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by Sourcery
Normalize struct binder db tag handling and add coverage for underscore and case-insensitive column mappings.
Bug Fixes:
Tests: