Skip to content

Commit 28e8912

Browse files
authored
Merge pull request #16 from dipdup-io/ignore-fields-with-huphen-in-pg
2 parents 2d85455 + 0e3d2ec commit 28e8912

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

database/comment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ func MakeComments(ctx context.Context, sc SchemeCommenter, models ...interface{}
4040
}
4141

4242
comment, ok := getComment(fieldType)
43-
if !ok {
43+
if !ok || comment == "" {
4444
continue
4545
}
4646

4747
columnName, ok := getPgName(fieldType)
48+
49+
if columnName == "-" {
50+
continue
51+
}
52+
4853
if !ok {
4954
columnName = hasura.ToSnakeCase(fieldType.Name)
5055
}

database/comment_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,53 @@ func TestMakeCommentsWithMultipleModelsByPointers(t *testing.T) {
212212
// Assert
213213
assert.Empty(t, err)
214214
}
215+
216+
func TestMakeCommentsIgnoreFieldWithPgHyphen(t *testing.T) {
217+
type Ballot struct {
218+
//nolint
219+
tableName struct{} `pg:"ballots"`
220+
Ballot string `json:"ballot" pg:"-" comment:"This is field comment"`
221+
}
222+
223+
mockCtrl, mockSC, ctx := initMocks(t)
224+
defer mockCtrl.Finish()
225+
226+
model := Ballot{}
227+
228+
// Assert prepare
229+
mockSC.
230+
EXPECT().
231+
MakeColumnComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
232+
Times(0)
233+
234+
// Act
235+
err := MakeComments(ctx, mockSC, model)
236+
237+
// Assert
238+
assert.Empty(t, err)
239+
}
240+
241+
func TestMakeCommentsIgnoreFieldsWithEmptyComment(t *testing.T) {
242+
type Ballot struct {
243+
//nolint
244+
tableName struct{} `pg:"ballots"`
245+
Ballot string `json:"ballot" comment:""`
246+
}
247+
248+
mockCtrl, mockSC, ctx := initMocks(t)
249+
defer mockCtrl.Finish()
250+
251+
model := Ballot{}
252+
253+
// Assert prepare
254+
mockSC.
255+
EXPECT().
256+
MakeColumnComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
257+
Times(0)
258+
259+
// Act
260+
err := MakeComments(ctx, mockSC, model)
261+
262+
// Assert
263+
assert.Empty(t, err)
264+
}

0 commit comments

Comments
 (0)