Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade gorm dependency in Turing API #261

Merged
merged 5 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ require (
github.com/gorilla/mux v1.8.0
github.com/gorilla/schema v1.1.0
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40
github.com/jinzhu/gorm v1.9.12
github.com/kelseyhightower/envconfig v1.4.0
github.com/mitchellh/copystructure v1.0.0
github.com/mitchellh/mapstructure v1.4.3
github.com/ory/viper v1.7.5
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.7.0
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.0
github.com/tidwall/gjson v1.6.5
github.com/xanzy/go-gitlab v0.31.0
go.uber.org/zap v1.19.1
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/postgres v1.4.4
gorm.io/gorm v1.24.0
gotest.tools v2.2.0+incompatible
gotest.tools/v3 v3.0.3
istio.io/api v0.0.0-20220304035241-8c47cbbea144
Expand Down Expand Up @@ -106,7 +107,16 @@ require (
github.com/hashicorp/vault/sdk v0.1.13 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
Expand Down Expand Up @@ -141,7 +151,7 @@ require (
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tidwall/match v1.0.3 // indirect
github.com/tidwall/pretty v1.0.2 // indirect
Expand All @@ -151,14 +161,13 @@ require (
go.mongodb.org/mongo-driver v1.1.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.12 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 // indirect
Expand Down
75 changes: 57 additions & 18 deletions api/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/turing/api/appcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/caraml-dev/turing/api/turing/service"
"github.com/caraml-dev/turing/engines/router/missionctl/errors"
"github.com/gojek/mlp/api/pkg/vault"
"github.com/jinzhu/gorm"
"gorm.io/gorm"
)

// AppContext stores the entities relating to the application's context
Expand Down
2 changes: 1 addition & 1 deletion api/turing/api/appcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
merlin "github.com/gojek/merlin/client"
"github.com/gojek/mlp/api/pkg/instrumentation/sentry"
"github.com/gojek/mlp/api/pkg/vault"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/assert"
"github.com/xanzy/go-gitlab"
"gorm.io/gorm"
"k8s.io/apimachinery/pkg/api/resource"
)

Expand Down
14 changes: 7 additions & 7 deletions api/turing/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (

"github.com/caraml-dev/turing/api/turing/config"
"github.com/golang-migrate/migrate/v4"
"github.com/jinzhu/gorm"
pg "gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"

// required for gomigrate
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/source/file"

// enable postgres dialect
_ "github.com/jinzhu/gorm/dialects/postgres"
)

// InitDB initialises a database connection as well as runs the migration scripts.
Expand All @@ -26,15 +25,16 @@ func InitDB(cfg *config.DatabaseConfig) (*gorm.DB, error) {

// Init db
db, err := gorm.Open(
"postgres",
connectionString(cfg),
pg.Open(connectionString(cfg)),
&gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
},
)

if err != nil {
return nil, fmt.Errorf("Failed to start Gorm DB: %s", err)
}

db.LogMode(false)
return db, nil
}

Expand Down
11 changes: 9 additions & 2 deletions api/turing/database/integration_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

"github.com/caraml-dev/turing/api/turing/config"
"github.com/caraml-dev/turing/api/turing/log"
"github.com/jinzhu/gorm"
pg "gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

func create(testDBCfg *config.DatabaseConfig) (*sql.DB, *sql.DB, error) {
Expand Down Expand Up @@ -57,7 +59,12 @@ func createTestDatabase() (*gorm.DB, func(), error) {
if err = migrateDB(testDBCfg); err != nil {
cleanup()
return nil, nil, err
} else if gormDb, err := gorm.Open("postgres", testDb); err != nil {
} else if gormDb, err := gorm.Open(
pg.New(pg.Config{Conn: testDb}),
&gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
},
); err != nil {
cleanup()
return nil, nil, err
} else {
Expand Down
2 changes: 1 addition & 1 deletion api/turing/models/ensembling_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"

openapi "github.com/caraml-dev/turing/api/turing/generated"
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
"gorm.io/gorm"
)

// EnsemblingJob holds the information required for an ensembling job to be done asynchronously
Expand Down
7 changes: 4 additions & 3 deletions api/turing/models/pyfunc_ensembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/jinzhu/gorm"
"gorm.io/gorm"
)

type EnsemblerLike interface {
Expand Down Expand Up @@ -89,8 +89,9 @@ type PyFuncEnsembler struct {
PythonVersion string `json:"python_version" gorm:"column:python_version"`
}

func (*PyFuncEnsembler) BeforeCreate(scope *gorm.Scope) error {
return scope.SetColumn("type", EnsemblerPyFuncType)
func (e *PyFuncEnsembler) BeforeCreate(*gorm.DB) error {
e.Type = EnsemblerPyFuncType
return nil
}

func (*PyFuncEnsembler) GetType() EnsemblerType {
Expand Down
2 changes: 1 addition & 1 deletion api/turing/models/router_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package models
import (
"database/sql"

"github.com/jinzhu/gorm"
"gorm.io/gorm"
)

type RouterVersionStatus string
Expand Down
8 changes: 6 additions & 2 deletions api/turing/server/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func Run() {
if err != nil {
panic(err)
}
defer db.Close()
sqlDB, err := db.DB()
if err != nil {
panic(err)
}
defer sqlDB.Close()

// Initialise NewRelic
if err := newrelic.InitNewRelic(cfg.NewRelicConfig); err != nil {
Expand Down Expand Up @@ -115,7 +119,7 @@ func Run() {
r := mux.NewRouter()

// HealthCheck Handler
AddHealthCheckHandler(r, "/v1/internal", db)
AddHealthCheckHandler(r, "/v1/internal", sqlDB)

// Write to a file so that Swagger UI can use it
err = cfg.OpenapiConfig.GenerateSpecFile()
Expand Down
6 changes: 3 additions & 3 deletions api/turing/server/healthcheck.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package server

import (
"database/sql"
"time"

"github.com/gorilla/mux"
"github.com/heptiolabs/healthcheck"
"github.com/jinzhu/gorm"
)

func AddHealthCheckHandler(r *mux.Router, path string, db *gorm.DB) {
func AddHealthCheckHandler(r *mux.Router, path string, db *sql.DB) {
sub := r.PathPrefix(path).Subrouter()

health := healthcheck.NewHandler()
health.AddReadinessCheck(
"database",
healthcheck.DatabasePingCheck(db.DB(), 1*time.Second))
healthcheck.DatabasePingCheck(db, 1*time.Second))

sub.Path("/live").HandlerFunc(health.LiveEndpoint)
sub.Path("/ready").HandlerFunc(health.ReadyEndpoint)
Expand Down
2 changes: 1 addition & 1 deletion api/turing/service/alert_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

"github.com/caraml-dev/turing/api/turing/log"
"github.com/caraml-dev/turing/api/turing/models"
"github.com/jinzhu/gorm"
"github.com/xanzy/go-gitlab"
"gopkg.in/yaml.v2"
"gorm.io/gorm"
)

type Metric string
Expand Down
Loading