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 efb155f commit a050b2e
Showing 1 changed file with 8 additions and 0 deletions.
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 IF EXISTS evm.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);
DROP INDEX IF EXISTS evm.idx_evm_logs_block_hash_log_index_evm_chain_id;
ALTER TABLE evm.logs DROP COLUMN id;
ALTER TABLE evm.logs ADD PRIMARY KEY (block_hash, log_index, evm_chain_id);


0 comments on commit a050b2e

Please sign in to comment.