Skip to content

Commit

Permalink
NewConnection shutdownSignal param is unused
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Sep 23, 2021
1 parent c68406d commit 0379911
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion core/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (n ChainlinkAppFactory) NewApplication(cfg config.GeneralConfig) (chainlink
shutdownSignal := gracefulpanic.NewSignal()
uri := cfg.DatabaseURL()
dialect := cfg.GetDatabaseDialectConfiguredOrDefault()
db, gormDB, err := postgres.NewConnection(uri.String(), string(dialect), cfg, shutdownSignal)
db, gormDB, err := postgres.NewConnection(uri.String(), string(dialect), cfg)
if err != nil {
return nil, err
}
Expand Down
24 changes: 9 additions & 15 deletions core/cmd/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
gormpostgres "gorm.io/driver/postgres"
"gorm.io/gorm"

"github.com/smartcontractkit/chainlink/core/gracefulpanic"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/services/bulletprooftxmanager"
"github.com/smartcontractkit/chainlink/core/services/chainlink"
Expand Down Expand Up @@ -445,7 +444,7 @@ func (cli *Client) RollbackDatabase(c *clipkg.Context) error {
return cli.errorOut(errors.New("You must set DATABASE_URL env variable. HINT: If you are running this to set up your local test database, try DATABASE_URL=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable"))
}

db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg, gracefulpanic.NewSignal())
db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg)
if err != nil {
return fmt.Errorf("failed to initialize orm: %v", err)
}
Expand All @@ -466,7 +465,7 @@ func (cli *Client) VersionDatabase(c *clipkg.Context) error {
return cli.errorOut(errors.New("You must set DATABASE_URL env variable. HINT: If you are running this to set up your local test database, try DATABASE_URL=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable"))
}

db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg, gracefulpanic.NewSignal())
db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg)
if err != nil {
return fmt.Errorf("failed to initialize orm: %v", err)
}
Expand All @@ -489,7 +488,7 @@ func (cli *Client) StatusDatabase(c *clipkg.Context) error {
return cli.errorOut(errors.New("You must set DATABASE_URL env variable. HINT: If you are running this to set up your local test database, try DATABASE_URL=postgresql://postgres@localhost:5432/chainlink_test?sslmode=disable"))
}

db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg, gracefulpanic.NewSignal())
db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg)
if err != nil {
return fmt.Errorf("failed to initialize orm: %v", err)
}
Expand All @@ -513,7 +512,7 @@ func (cli *Client) CreateMigration(c *clipkg.Context) error {
return cli.errorOut(errors.New("You must specify a migration name"))
}

db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg, gracefulpanic.NewSignal())
db, _, err := postgres.NewConnection(parsed.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg)
if err != nil {
return fmt.Errorf("failed to initialize orm: %v", err)
}
Expand Down Expand Up @@ -557,7 +556,7 @@ func dropAndCreateDB(parsed url.URL) (err error) {

func migrateDB(config config.GeneralConfig) error {
dbURL := config.DatabaseURL()
db, _, err := postgres.NewConnection(dbURL.String(), string(config.GetDatabaseDialectConfiguredOrDefault()), config, gracefulpanic.NewSignal())
db, _, err := postgres.NewConnection(dbURL.String(), string(config.GetDatabaseDialectConfiguredOrDefault()), config)
if err != nil {
return fmt.Errorf("failed to initialize orm: %v", err)
}
Expand All @@ -569,22 +568,17 @@ func migrateDB(config config.GeneralConfig) error {

func downAndUpDB(cfg config.GeneralConfig, baseVersionID int64) error {
dbURL := cfg.DatabaseURL()
orm, err := orm.NewORM(dbURL.String(), cfg.DatabaseTimeout(), gracefulpanic.NewSignal(), cfg.GetDatabaseDialectConfiguredOrDefault(), cfg.GetAdvisoryLockIDConfiguredOrDefault(), cfg.GlobalLockRetryInterval().Duration(), cfg.ORMMaxOpenConns(), cfg.ORMMaxIdleConns())
db, _, err := postgres.NewConnection(dbURL.String(), string(config.GetDatabaseDialectConfiguredOrDefault()), config)
if err != nil {
return fmt.Errorf("failed to initialize orm: %v", err)
}
orm.SetLogging(cfg.LogSQLStatements() || cfg.LogSQLMigrations())

db := postgres.UnwrapGormDB(orm.DB).DB

if err = migrate.Rollback(db, null.IntFrom(baseVersionID)); err != nil {
if err = migrate.Rollback(db.DB, null.IntFrom(baseVersionID)); err != nil {
return fmt.Errorf("test rollback failed: %v", err)
}
if err = migrate.Migrate(db); err != nil {
if err = migrate.Migrate(db.DB); err != nil {
return fmt.Errorf("second migrateDB failed: %v", err)
}
orm.SetLogging(cfg.LogSQLStatements())
return orm.Close()
return db.Close()
}

func dumpSchema(cfg config.GeneralConfig) (string, error) {
Expand Down
5 changes: 3 additions & 2 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
evmconfig "github.com/smartcontractkit/chainlink/core/chains/evm/config"
evmtypes "github.com/smartcontractkit/chainlink/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/core/cmd"
"github.com/smartcontractkit/chainlink/core/gracefulpanic"
"github.com/smartcontractkit/chainlink/core/internal/gethwrappers/generated/flux_aggregator_wrapper"
"github.com/smartcontractkit/chainlink/core/internal/mocks"
"github.com/smartcontractkit/chainlink/core/logger"
Expand Down Expand Up @@ -334,10 +335,10 @@ func NewApplicationWithConfig(t testing.TB, cfg *configtest.TestGeneralConfig, f
var ethClient eth.Client = &eth.NullClient{}

var eventBroadcaster postgres.EventBroadcaster = postgres.NewNullEventBroadcaster()
shutdownSignal := &testShutdownSignal{t}
shutdownSignal := gracefulpanic.NewSignal()

url := cfg.DatabaseURL()
sqlxDB, db, err := postgres.NewConnection(url.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg, shutdownSignal)
sqlxDB, db, err := postgres.NewConnection(url.String(), string(cfg.GetDatabaseDialectConfiguredOrDefault()), cfg)
require.NoError(t, err)

var externalInitiatorManager webhook.ExternalInitiatorManager
Expand Down
3 changes: 1 addition & 2 deletions core/internal/cltest/heavyweight/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"runtime"
"testing"

"github.com/smartcontractkit/chainlink/core/gracefulpanic"
"github.com/smartcontractkit/chainlink/core/internal/cltest"
"github.com/smartcontractkit/chainlink/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/core/services/postgres"
Expand All @@ -40,7 +39,7 @@ func FullTestDB(t *testing.T, name string, migrate bool, loadFixtures bool) (*co
require.NoError(t, os.MkdirAll(gcfg.RootDir(), 0700))
migrationTestDBURL, err := dropAndCreateThrowawayTestDB(gcfg.DatabaseURL(), name)
require.NoError(t, err)
db, gormDB, err := postgres.NewConnection(migrationTestDBURL, string(dialects.Postgres), gcfg, gracefulpanic.NewSignal())
db, gormDB, err := postgres.NewConnection(migrationTestDBURL, string(dialects.Postgres), gcfg)
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, db.Close())
Expand Down
3 changes: 1 addition & 2 deletions core/services/postgres/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
uuid "github.com/satori/go.uuid"
"github.com/scylladb/go-reflectx"

"github.com/smartcontractkit/chainlink/core/gracefulpanic"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/store/config"

Expand All @@ -23,7 +22,7 @@ import (
_ "github.com/jackc/pgx/v4"
)

func NewConnection(uri string, dialect string, cfg config.GeneralConfig, shutdownSignal gracefulpanic.Signal) (db *sqlx.DB, gormDB *gorm.DB, err error) {
func NewConnection(uri string, dialect string, cfg config.GeneralConfig) (db *sqlx.DB, gormDB *gorm.DB, err error) {
originalURI := uri
if dialect == "txdb" {
// Dbtx uses the uri as a unique identifier for each transaction. Each ORM
Expand Down

0 comments on commit 0379911

Please sign in to comment.