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

Migration logging can be enabled independently of all sql logging #1563

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func NewConfigWithWSServer(t testing.TB, wsserver *httptest.Server) *TestConfig
rawConfig.Set("CHAINLINK_DEV", true)
rawConfig.Set("ETH_GAS_BUMP_THRESHOLD", 3)
rawConfig.Set("LOG_LEVEL", orm.LogLevel{Level: zapcore.DebugLevel})
rawConfig.Set("LOG_SQL", false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

rawConfig.Set("LOG_SQL_MIGRATIONS", false)
rawConfig.Set("MINIMUM_SERVICE_DURATION", "24h")
rawConfig.Set("MIN_INCOMING_CONFIRMATIONS", 1)
rawConfig.Set("MIN_OUTGOING_CONFIRMATIONS", 6)
Expand Down
1 change: 0 additions & 1 deletion core/store/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func Migrate(db *gorm.DB) error {
},
}

db.LogMode(true)
m := gormigrate.New(db, &options, migrations)

var count int
Expand Down
4 changes: 2 additions & 2 deletions core/store/migrations/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func bootstrapORM(t *testing.T) (*orm.ORM, func()) {

orm, err := orm.NewORM(orm.NormalizedDatabaseURL(config), config.DatabaseTimeout())
require.NoError(t, err)
orm.DB.LogMode(true)

return orm, func() {
assert.NoError(t, orm.Close())
Expand Down Expand Up @@ -185,6 +186,7 @@ func TestMigrate_Migration1560881846(t *testing.T) {
func TestMigrate_Migration1565139192(t *testing.T) {
orm, cleanup := bootstrapORM(t)
defer cleanup()

db := orm.DB

require.NoError(t, migration0.Migrate(db))
Expand All @@ -209,7 +211,6 @@ func TestMigrate_Migration1565210496(t *testing.T) {
defer cleanup()

db := orm.DB
db.LogMode(true)

require.NoError(t, migration0.Migrate(db))

Expand Down Expand Up @@ -239,7 +240,6 @@ func TestMigrate_Migration1565291711(t *testing.T) {
defer cleanup()

db := orm.DB
db.LogMode(true)

require.NoError(t, migration0.Migrate(db))
require.NoError(t, migration1560881855.Migrate(db))
Expand Down
5 changes: 5 additions & 0 deletions core/store/orm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ func (c Config) LogSQLStatements() bool {
return c.viper.GetBool(EnvVarName("LogSQLStatements"))
}

// LogSQLMigrations tells chainlink to log all SQL migrations made using the default logger
func (c Config) LogSQLMigrations() bool {
return c.viper.GetBool(EnvVarName("LogSQLMigrations"))
}

// MinIncomingConfirmations represents the minimum number of block
// confirmations that need to be recorded since a job run started before a task
// can proceed.
Expand Down
1 change: 1 addition & 0 deletions core/store/orm/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ConfigSchema struct {
LogLevel LogLevel `env:"LOG_LEVEL" default:"info"`
LogToDisk bool `env:"LOG_TO_DISK" default:"true"`
LogSQLStatements bool `env:"LOG_SQL" default:"false"`
LogSQLMigrations bool `env:"LOG_SQL_MIGRATIONS" default:"true"`
MinIncomingConfirmations uint32 `env:"MIN_INCOMING_CONFIRMATIONS" default:"3"`
MinOutgoingConfirmations uint64 `env:"MIN_OUTGOING_CONFIRMATIONS" default:"12"`
MinimumContractPayment assets.Link `env:"MINIMUM_CONTRACT_PAYMENT" default:"1000000000000000000"`
Expand Down
8 changes: 6 additions & 2 deletions core/store/presenters/presenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,18 @@ type whitelist struct {
BridgeResponseURL string `json:"bridgeResponseURL,omitempty"`
ChainID *big.Int `json:"ethChainId"`
ClientNodeURL string `json:"clientNodeUrl"`
Dev bool `json:"chainlinkDev"`
DatabaseTimeout time.Duration `json:"databaseTimeout"`
Dev bool `json:"chainlinkDev"`
EthereumURL string `json:"ethUrl"`
EthGasBumpThreshold uint64 `json:"ethGasBumpThreshold"`
EthGasBumpWei *big.Int `json:"ethGasBumpWei"`
EthGasPriceDefault *big.Int `json:"ethGasPriceDefault"`
ExplorerURL string `json:"explorerUrl"`
JSONConsole bool `json:"jsonConsole"`
LinkContractAddress string `json:"linkContractAddress"`
ExplorerURL string `json:"explorerUrl"`
LogLevel orm.LogLevel `json:"logLevel"`
LogSQLMigrations bool `json:"logSqlMigrations"`
LogSQLStatements bool `json:"logSqlStatements"`
LogToDisk bool `json:"logToDisk"`
MinimumContractPayment *assets.Link `json:"minimumContractPayment"`
MinimumRequestExpiration uint64 `json:"minimumRequestExpiration"`
Expand Down Expand Up @@ -182,6 +184,8 @@ func NewConfigWhitelist(store *store.Store) (ConfigWhitelist, error) {
ExplorerURL: explorerURL,
LogLevel: config.LogLevel(),
LogToDisk: config.LogToDisk(),
LogSQLStatements: config.LogSQLStatements(),
LogSQLMigrations: config.LogSQLMigrations(),
MinimumContractPayment: config.MinimumContractPayment(),
MinimumRequestExpiration: config.MinimumRequestExpiration(),
MinIncomingConfirmations: config.MinIncomingConfirmations(),
Expand Down
1 change: 1 addition & 0 deletions core/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func initializeORM(config *orm.Config) (*orm.ORM, error) {
if err != nil {
return nil, errors.Wrap(err, "initializeORM#NewORM")
}
orm.SetLogging(config.LogSQLStatements() || config.LogSQLMigrations())
if err = migrations.Migrate(orm.DB); err != nil {
return nil, errors.Wrap(err, "initializeORM#Migrate")
}
Expand Down