Skip to content

Commit

Permalink
Set the primary key types to int32
Browse files Browse the repository at this point in the history
This matches the serial primary key option of values
1 to 2147483647.

Signed-off-by: mprahl <[email protected]>
(cherry picked from commit 3835e6e)
  • Loading branch information
mprahl authored and Magic Mirror committed Jan 5, 2024
1 parent 06e3417 commit edbd7be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions controllers/complianceeventsapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ func postComplianceEvent(db *sql.DB, w http.ResponseWriter, r *http.Request) {
}
}

func getClusterForeignKey(ctx context.Context, db *sql.DB, cluster Cluster) (int, error) {
func getClusterForeignKey(ctx context.Context, db *sql.DB, cluster Cluster) (int32, error) {
// Check cache
key, ok := clusterKeyCache.Load(cluster.ClusterID)
if ok {
return key.(int), nil
return key.(int32), nil
}

err := cluster.GetOrCreate(ctx, db)
Expand All @@ -200,13 +200,13 @@ func getClusterForeignKey(ctx context.Context, db *sql.DB, cluster Cluster) (int
return cluster.KeyID, nil
}

func getParentPolicyForeignKey(ctx context.Context, db *sql.DB, parent ParentPolicy) (int, error) {
func getParentPolicyForeignKey(ctx context.Context, db *sql.DB, parent ParentPolicy) (int32, error) {
// Check cache
parKey := parent.key()

key, ok := parentPolicyKeyCache.Load(parKey)
if ok {
return key.(int), nil
return key.(int32), nil
}

err := parent.GetOrCreate(ctx, db)
Expand All @@ -219,7 +219,7 @@ func getParentPolicyForeignKey(ctx context.Context, db *sql.DB, parent ParentPol
return parent.KeyID, nil
}

func getPolicyForeignKey(ctx context.Context, db *sql.DB, pol Policy) (int, error) {
func getPolicyForeignKey(ctx context.Context, db *sql.DB, pol Policy) (int32, error) {
// Fill in missing fields that can be inferred from other fields
if pol.SpecHash == "" {
var buf bytes.Buffer
Expand All @@ -236,7 +236,7 @@ func getPolicyForeignKey(ctx context.Context, db *sql.DB, pol Policy) (int, erro

key, ok := policyKeyCache.Load(polKey)
if ok {
return key.(int), nil
return key.(int32), nil
}

if pol.Spec == "" {
Expand Down
16 changes: 8 additions & 8 deletions controllers/complianceeventsapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (ce *ComplianceEvent) Create(ctx context.Context, db *sql.DB) error {
}

type Cluster struct {
KeyID int `db:"id" json:"-"`
KeyID int32 `db:"id" json:"-"`
Name string `db:"name" json:"name"`
ClusterID string `db:"cluster_id" json:"cluster_id"` //nolint:tagliatelle
}
Expand Down Expand Up @@ -132,10 +132,10 @@ func (c *Cluster) GetOrCreate(ctx context.Context, db *sql.DB) error {
}

type EventDetails struct {
KeyID int `db:"id" json:"-"`
ClusterID int `db:"cluster_id" json:"-"`
PolicyID int `db:"policy_id" json:"-"`
ParentPolicyID *int `db:"parent_policy_id" json:"-"`
KeyID int32 `db:"id" json:"-"`
ClusterID int32 `db:"cluster_id" json:"-"`
PolicyID int32 `db:"policy_id" json:"-"`
ParentPolicyID *int32 `db:"parent_policy_id" json:"-"`
Compliance string `db:"compliance" json:"compliance"`
Message string `db:"message" json:"message"`
Timestamp time.Time `db:"timestamp" json:"timestamp"`
Expand Down Expand Up @@ -180,7 +180,7 @@ func (e *EventDetails) InsertQuery() (string, []any) {
}

type ParentPolicy struct {
KeyID int `db:"id" json:"-"`
KeyID int32 `db:"id" json:"-"`
Name string `db:"name" json:"name"`
Namespace string `db:"namespace" json:"namespace"`
Categories pq.StringArray `db:"categories" json:"categories,omitempty"`
Expand Down Expand Up @@ -235,7 +235,7 @@ func (p ParentPolicy) key() string {
}

type Policy struct {
KeyID int `db:"id" json:"-"`
KeyID int32 `db:"id" json:"-"`
Kind string `db:"kind" json:"kind"`
APIGroup string `db:"api_group" json:"apiGroup"`
Name string `db:"name" json:"name"`
Expand Down Expand Up @@ -381,7 +381,7 @@ func getOrCreate(ctx context.Context, db *sql.DB, obj dbRow) error {
return row.Err()
}

var primaryKey int
var primaryKey int32

err := row.Scan(&primaryKey)
if errors.Is(err, sql.ErrNoRows) {
Expand Down

0 comments on commit edbd7be

Please sign in to comment.