Skip to content

Commit

Permalink
Add UNIQUE INDEXes to replace previous primary keys
Browse files Browse the repository at this point in the history
This was causing duplicate rows to get inserted during a replay
instead of it being an UPDATE
  • Loading branch information
reductionista committed Aug 21, 2024
1 parent db26cb1 commit ca7b2d5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/store/migrate/migrations/0248_log_poller_primary_keys.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

ALTER TABLE evm.logs DROP CONSTRAINT logs_pkey;
ALTER TABLE evm.logs ADD COLUMN id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY;
CREATE UNIQUE INDEX idx_evm_logs_block_hash_log_index_evm_chain_id ON evm.logs (block_hash, log_index, evm_chain_id);
ALTER TABLE evm.log_poller_blocks DROP CONSTRAINT log_poller_blocks_pkey;
ALTER TABLE evm.log_poller_blocks ADD COLUMN id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY;
CREATE UNIQUE INDEX idx_evm_log_poller_blocks_block_number_evm_chain_id ON evm.log_poller_blocks (block_number, evm_chain_id);

-- TODO: restore UNIQUE constratint on original pkey!

-- +goose Down

DROP INDEX idx_evm_log_poller_blocks_block_number_evm_chain_id;
ALTER TABLE evm.log_poller_blocks DROP COLUMN id;
ALTER TABLE evm.log_poller_blocks ADD PRIMARY KEY (block_number, evm_chain_id);
ALTER TABLE evm.logs DROP COLUMN id;
DROP INDEX idx_evm_logs_block_hash_log_index_evm_chain_id;
dALTER TABLE evm.logs DROP COLUMN id;
ALTER TABLE evm.logs ADD PRIMARY KEY (block_hash, log_index, evm_chain_id);


0 comments on commit ca7b2d5

Please sign in to comment.