forked from cerc-io/ipld-eth-server
Associate receipts with blocks instead of transactions
- Allows us to fetch receipts by block and persist even when associated transaction is unknown. (The associated transaction can still be derived from the tx_hash column at query time, but is an expensive operation to require for inserts).
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE receipts
|
||||
ADD COLUMN transaction_id INT;
|
||||
|
||||
UPDATE receipts
|
||||
SET transaction_id = (
|
||||
SELECT id FROM transactions WHERE transactions.hash = receipts.tx_hash
|
||||
);
|
||||
|
||||
ALTER TABLE receipts
|
||||
ALTER COLUMN transaction_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE receipts
|
||||
ADD CONSTRAINT transaction_fk
|
||||
FOREIGN KEY (transaction_id)
|
||||
REFERENCES transactions (id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE receipts
|
||||
DROP COLUMN block_id;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,23 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE receipts
|
||||
ADD COLUMN block_id INT;
|
||||
|
||||
UPDATE receipts
|
||||
SET block_id = (
|
||||
SELECT block_id FROM transactions WHERE transactions.id = receipts.transaction_id
|
||||
);
|
||||
|
||||
ALTER TABLE receipts
|
||||
ALTER COLUMN block_id SET NOT NULL;
|
||||
|
||||
ALTER TABLE receipts
|
||||
ADD CONSTRAINT blocks_fk
|
||||
FOREIGN KEY (block_id)
|
||||
REFERENCES blocks (id)
|
||||
ON DELETE CASCADE;
|
||||
|
||||
ALTER TABLE receipts
|
||||
DROP COLUMN transaction_id;
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user