diff --git a/database/comment.go b/database/comment.go index a7f5d9d..acae2e3 100644 --- a/database/comment.go +++ b/database/comment.go @@ -40,11 +40,16 @@ func MakeComments(ctx context.Context, sc SchemeCommenter, models ...interface{} } comment, ok := getComment(fieldType) - if !ok { + if !ok || comment == "" { continue } columnName, ok := getPgName(fieldType) + + if columnName == "-" { + continue + } + if !ok { columnName = hasura.ToSnakeCase(fieldType.Name) } diff --git a/database/comment_test.go b/database/comment_test.go index 1bd9110..befe69c 100644 --- a/database/comment_test.go +++ b/database/comment_test.go @@ -212,3 +212,53 @@ func TestMakeCommentsWithMultipleModelsByPointers(t *testing.T) { // Assert assert.Empty(t, err) } + +func TestMakeCommentsIgnoreFieldWithPgHyphen(t *testing.T) { + type Ballot struct { + //nolint + tableName struct{} `pg:"ballots"` + Ballot string `json:"ballot" pg:"-" comment:"This is field comment"` + } + + mockCtrl, mockSC, ctx := initMocks(t) + defer mockCtrl.Finish() + + model := Ballot{} + + // Assert prepare + mockSC. + EXPECT(). + MakeColumnComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Times(0) + + // Act + err := MakeComments(ctx, mockSC, model) + + // Assert + assert.Empty(t, err) +} + +func TestMakeCommentsIgnoreFieldsWithEmptyComment(t *testing.T) { + type Ballot struct { + //nolint + tableName struct{} `pg:"ballots"` + Ballot string `json:"ballot" comment:""` + } + + mockCtrl, mockSC, ctx := initMocks(t) + defer mockCtrl.Finish() + + model := Ballot{} + + // Assert prepare + mockSC. + EXPECT(). + MakeColumnComment(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + Times(0) + + // Act + err := MakeComments(ctx, mockSC, model) + + // Assert + assert.Empty(t, err) +}