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

BCF-2637 Add evm chain id removal migrations #10669

Merged
merged 15 commits into from
Sep 18, 2023
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package migrations

import (
"context"
"database/sql"

"github.com/pressly/goose/v3"

"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
)

func init() {
goose.AddMigrationContext(Up195, Down195)
}

const (
up195_1 = `
ilija42 marked this conversation as resolved.
Show resolved Hide resolved
UPDATE direct_request_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
ilija42 marked this conversation as resolved.
Show resolved Hide resolved
UPDATE flux_monitor_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
UPDATE ocr_oracle_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
UPDATE keeper_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
UPDATE vrf_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
UPDATE blockhash_store_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
UPDATE block_header_feeder_specs SET evm_chain_id = '%d' WHERE evm_chain_id IS NULL;
`
up195_2 = `
ALTER TABLE direct_request_specs ALTER COLUMN evm_chain_id SET NOT NULL;
ALTER TABLE flux_monitor_specs ALTER COLUMN evm_chain_id SET NOT NULL;
ALTER TABLE ocr_oracle_specs ALTER COLUMN evm_chain_id SET NOT NULL;
ALTER TABLE keeper_specs ALTER COLUMN evm_chain_id SET NOT NULL;
ALTER TABLE vrf_specs ALTER COLUMN evm_chain_id SET NOT NULL;
ALTER TABLE blockhash_store_specs ALTER COLUMN evm_chain_id SET NOT NULL;
ALTER TABLE block_header_feeder_specs ALTER COLUMN evm_chain_id SET NOT NULL;
`

down195 = `
ALTER TABLE direct_request_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
ALTER TABLE flux_monitor_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
ALTER TABLE ocr_oracle_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
ALTER TABLE keeper_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
ALTER TABLE vrf_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
ALTER TABLE blockhash_store_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
ALTER TABLE block_header_feeder_specs ALTER COLUMN evm_chain_id DROP NOT NULL;
`
)

// nolint
func Up195(ctx context.Context, tx *sql.Tx) error {
var opts chainlink.GeneralConfigOpts
cfg, err := opts.New()
ilija42 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

if cfg.EVMEnabled() {
chainID := cfg.EVMConfigs()[0].ChainID
_, err = tx.ExecContext(ctx, up195_1, chainID)
if err != nil {
return err
}
}

_, err = tx.ExecContext(ctx, up195_2)
return err
}

// nolint
func Down195(ctx context.Context, tx *sql.Tx) error {
if _, err := tx.ExecContext(ctx, down195); err != nil {
return err
}
return nil
}