Skip to content

Commit bcece24

Browse files
author
Keerthan Mala
committed
use string instead of types.JSONText in the gorm table structs
1 parent 0c05858 commit bcece24

6 files changed

+14
-18
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DEV_ENV_IMAGE := quay.io/deis/go-dev:0.9.1
1212
SWAGGER_IMAGE := quay.io/goswagger/swagger:0.5.0
1313
DEV_ENV_WORK_DIR := /go/src/${REPO_PATH}
1414
DEV_ENV_PREFIX := docker run --rm -e GO15VENDOREXPERIMENT=1 -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR}
15-
DEV_ENV_CMD := ${DEV_ENV_PREFIX} -e GODEBUG=cgocheck=0 ${DEV_ENV_IMAGE}
15+
DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE}
1616
SWAGGER_CMD := docker run --rm -e GOPATH=/go -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR} ${SWAGGER_IMAGE}
1717

1818
# SemVer with build information is defined in the SemVer 2 spec, but Docker

pkg/data/cluster.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func GetCluster(db *gorm.DB, id string) (models.Cluster, error) {
2929
if resDB.Error != nil {
3030
return models.Cluster{}, resDB.Error
3131
}
32-
cluster, err := parseJSONCluster(ret.Data)
32+
cluster, err := parseJSONCluster([]byte(ret.Data))
3333
if err != nil {
3434
return models.Cluster{}, errParsingCluster{origErr: err}
3535
}
@@ -54,13 +54,13 @@ func upsertCluster(db *gorm.DB, id string, cluster models.Cluster) (models.Clust
5454
var resDB *gorm.DB
5555
if numExisting == 0 {
5656
// no existing clusters, so create one
57-
createDB := db.Create(&clustersTable{ClusterID: id, Data: js})
57+
createDB := db.Create(&clustersTable{ClusterID: id, Data: string(js)})
5858
if createDB.Error != nil {
5959
return models.Cluster{}, createDB.Error
6060
}
6161
resDB = createDB
6262
} else {
63-
updateDB := db.Save(&clustersTable{ClusterID: id, Data: js})
63+
updateDB := db.Save(&clustersTable{ClusterID: id, Data: string(js)})
6464
if updateDB.Error != nil {
6565
return models.Cluster{}, updateDB.Error
6666
}
@@ -138,7 +138,7 @@ func FilterClustersByAge(db *gorm.DB, filter *ClusterAgeFilter) ([]*models.Clust
138138

139139
clusters := make([]*models.Cluster, len(rows))
140140
for i, row := range rows {
141-
cluster, err := parseJSONCluster(row.Data)
141+
cluster, err := parseJSONCluster([]byte(row.Data))
142142
if err != nil {
143143
return nil, err
144144
}

pkg/data/cluster_count_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestGetClusterCount(t *testing.T) {
1212
count, err := GetClusterCount(db)
1313
assert.NoErr(t, err)
1414
assert.Equal(t, count, 0, "count")
15-
d1 := db.Create(&clustersTable{ClusterID: uuid.New(), Data: []byte("{}")})
15+
d1 := db.Create(&clustersTable{ClusterID: uuid.New(), Data: "{}"})
1616
assert.NoErr(t, d1.Error)
1717
count, err = GetClusterCount(d1)
1818
assert.NoErr(t, err)

pkg/data/cluster_filter_by_age_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func createAndCheckinClusters(db *gorm.DB, totalNumClusters, filterNum int, fca
130130
if marshalErr != nil {
131131
return fmt.Errorf("error JSON serializing cluster %d for filter %d (%s)", clusterNum, filterNum, marshalErr)
132132
}
133-
createDB := db.Model(&clustersTable{}).Create(&clustersTable{ClusterID: cluster.ID, Data: clusterJSON})
133+
createDB := db.Model(&clustersTable{}).Create(&clustersTable{ClusterID: cluster.ID, Data: string(clusterJSON)})
134134
if createDB.Error != nil {
135135
return fmt.Errorf("error creating cluster %s for filter %d in DB (%s)", cluster.ID, filterNum, createDB.Error)
136136
}

pkg/data/clusters_checkins_table.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"fmt"
66
"log"
77
"time"
8-
9-
"github.com/jmoiron/sqlx/types"
108
)
119

1210
const (
@@ -19,18 +17,18 @@ const (
1917

2018
// ClustersCheckinsTable type that expresses the `clusters_checkins` postgres table schema
2119
type clustersCheckinsTable struct {
22-
CheckinsID string `gorm:"primary_key;type:bigserial;column_name:checkins_id"`
23-
ClusterID string `gorm:"type:uuid;column_name:cluster_id;index"`
24-
CreatedAt string `gorm:"type:timestamp;column_name:created_at;index"`
25-
Data types.JSONText `gorm:"type:json;column_name:data"`
20+
CheckinsID string `gorm:"primary_key;type:bigserial;column_name:checkins_id"`
21+
ClusterID string `gorm:"type:uuid;column_name:cluster_id;index"`
22+
CreatedAt string `gorm:"type:timestamp;column_name:created_at;index"`
23+
Data string `gorm:"type:json;column_name:data"`
2624
}
2725

2826
func newClustersCheckinsTable(checkinID, clusterID string, createdAt time.Time, clusterData []byte) clustersCheckinsTable {
2927
return clustersCheckinsTable{
3028
CheckinsID: checkinID,
3129
ClusterID: clusterID,
3230
CreatedAt: Timestamp{Time: createdAt}.String(),
33-
Data: types.JSONText(clusterData),
31+
Data: string(clusterData),
3432
}
3533
}
3634

pkg/data/clusters_table.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"database/sql"
55
"fmt"
66
"log"
7-
8-
"github.com/jmoiron/sqlx/types"
97
)
108

119
const (
@@ -16,8 +14,8 @@ const (
1614

1715
// ClustersTable type that expresses the `clusters` postgres table schema
1816
type clustersTable struct {
19-
ClusterID string `gorm:"primary_key;type:uuid;column:cluster_id"` // PRIMARY KEY
20-
Data types.JSONText `gorm:"type:json;column:data"`
17+
ClusterID string `gorm:"primary_key;type:uuid;column:cluster_id"` // PRIMARY KEY
18+
Data string `gorm:"type:json;column:data"`
2119
}
2220

2321
func (c clustersTable) TableName() string {

0 commit comments

Comments
 (0)