ipld-eth-server/db/migrations/1525122581_associate_receipts_with_blocks.down.sql
Rob Mulholand 462f94d84a 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).
2018-05-04 10:52:28 -05:00

23 lines
435 B
PL/PgSQL

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;