ipld-eth-server/db/migrations/1525122581_associate_receipts_with_blocks.down.sql

23 lines
435 B
MySQL
Raw Normal View History

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;