Skip to content

Commit

Permalink
use int64 for DB reps of integer fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Sep 13, 2024
1 parent 7635576 commit 1864d01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions database/types/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Hook struct {
ID sql.NullInt64 `sql:"id"`
RepoID sql.NullInt64 `sql:"repo_id"`
BuildID sql.NullInt64 `sql:"build_id"`
Number sql.NullInt32 `sql:"number"`
Number sql.NullInt64 `sql:"number"`
SourceID sql.NullString `sql:"source_id"`
Created sql.NullInt64 `sql:"created"`
Host sql.NullString `sql:"host"`
Expand Down Expand Up @@ -76,7 +76,7 @@ func (h *Hook) Nullify() *Hook {
}

// check if the Number field should be false
if h.Number.Int32 == 0 {
if h.Number.Int64 == 0 {
h.Number.Valid = false
}

Expand Down Expand Up @@ -151,7 +151,7 @@ func (h *Hook) ToAPI() *api.Hook {

hook.SetID(h.ID.Int64)
hook.SetRepo(h.Repo.ToAPI())
hook.SetNumber(int(h.Number.Int32))
hook.SetNumber(int(h.Number.Int64))
hook.SetSourceID(h.SourceID.String)
hook.SetCreated(h.Created.Int64)
hook.SetHost(h.Host.String)
Expand All @@ -175,7 +175,7 @@ func (h *Hook) Validate() error {
}

// verify the Number field is populated
if h.Number.Int32 <= 0 {
if h.Number.Int64 <= 0 {
return ErrEmptyHookNumber
}

Expand Down Expand Up @@ -211,7 +211,7 @@ func HookFromAPI(h *api.Hook) *Hook {
ID: sql.NullInt64{Int64: h.GetID(), Valid: true},
RepoID: sql.NullInt64{Int64: h.GetRepo().GetID(), Valid: true},
BuildID: sql.NullInt64{Int64: h.GetBuild().GetID(), Valid: true},
Number: sql.NullInt32{Int32: int32(h.GetNumber()), Valid: true},
Number: sql.NullInt64{Int64: int64(h.GetNumber()), Valid: true},
SourceID: sql.NullString{String: h.GetSourceID(), Valid: true},
Created: sql.NullInt64{Int64: h.GetCreated(), Valid: true},
Host: sql.NullString{String: h.GetHost(), Valid: true},
Expand Down
12 changes: 6 additions & 6 deletions database/types/hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestTypes_Hook_Nullify(t *testing.T) {
ID: sql.NullInt64{Int64: 0, Valid: false},
RepoID: sql.NullInt64{Int64: 0, Valid: false},
BuildID: sql.NullInt64{Int64: 0, Valid: false},
Number: sql.NullInt32{Int32: 0, Valid: false},
Number: sql.NullInt64{Int64: 0, Valid: false},
SourceID: sql.NullString{String: "", Valid: false},
Created: sql.NullInt64{Int64: 0, Valid: false},
Host: sql.NullString{String: "", Valid: false},
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestTypes_Hook_Validate(t *testing.T) {
failure: true,
hook: &Hook{
ID: sql.NullInt64{Int64: 1, Valid: true},
Number: sql.NullInt32{Int32: 1, Valid: true},
Number: sql.NullInt64{Int64: 1, Valid: true},
SourceID: sql.NullString{String: "c8da1302-07d6-11ea-882f-4893bca275b8", Valid: true},
WebhookID: sql.NullInt64{Int64: 1, Valid: true},
},
Expand All @@ -125,7 +125,7 @@ func TestTypes_Hook_Validate(t *testing.T) {
failure: true,
hook: &Hook{
ID: sql.NullInt64{Int64: 1, Valid: true},
Number: sql.NullInt32{Int32: 1, Valid: true},
Number: sql.NullInt64{Int64: 1, Valid: true},
RepoID: sql.NullInt64{Int64: 1, Valid: true},
WebhookID: sql.NullInt64{Int64: 1, Valid: true},
},
Expand All @@ -134,7 +134,7 @@ func TestTypes_Hook_Validate(t *testing.T) {
failure: true,
hook: &Hook{
ID: sql.NullInt64{Int64: 1, Valid: true},
Number: sql.NullInt32{Int32: 1, Valid: true},
Number: sql.NullInt64{Int64: 1, Valid: true},
RepoID: sql.NullInt64{Int64: 1, Valid: true},
SourceID: sql.NullString{String: "c8da1302-07d6-11ea-882f-4893bca275b8", Valid: true},
},
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestTypes_HookFromAPI(t *testing.T) {
ID: sql.NullInt64{Int64: 1, Valid: true},
RepoID: sql.NullInt64{Int64: 1, Valid: true},
BuildID: sql.NullInt64{Int64: 1, Valid: true},
Number: sql.NullInt32{Int32: 1, Valid: true},
Number: sql.NullInt64{Int64: 1, Valid: true},
SourceID: sql.NullString{String: "c8da1302-07d6-11ea-882f-4893bca275b8", Valid: true},
Created: sql.NullInt64{Int64: time.Now().UTC().Unix(), Valid: true},
Host: sql.NullString{String: "github.com", Valid: true},
Expand Down Expand Up @@ -209,7 +209,7 @@ func testHook() *Hook {
ID: sql.NullInt64{Int64: 1, Valid: true},
RepoID: sql.NullInt64{Int64: 1, Valid: true},
BuildID: sql.NullInt64{Int64: 1, Valid: true},
Number: sql.NullInt32{Int32: 1, Valid: true},
Number: sql.NullInt64{Int64: 1, Valid: true},
SourceID: sql.NullString{String: "c8da1302-07d6-11ea-882f-4893bca275b8", Valid: true},
Created: sql.NullInt64{Int64: time.Now().UTC().Unix(), Valid: true},
Host: sql.NullString{String: "github.com", Valid: true},
Expand Down

0 comments on commit 1864d01

Please sign in to comment.