2019-01-22 12:15:29 +00:00
|
|
|
-- +goose Up
|
|
|
|
ALTER TABLE receipts
|
|
|
|
ADD COLUMN block_id INT;
|
|
|
|
|
|
|
|
UPDATE receipts
|
|
|
|
SET block_id = (
|
2019-03-19 19:11:26 +00:00
|
|
|
SELECT block_id FROM full_sync_transactions WHERE full_sync_transactions.id = receipts.transaction_id
|
2019-01-22 12:15:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
-- +goose Down
|
|
|
|
ALTER TABLE receipts
|
|
|
|
ADD COLUMN transaction_id INT;
|
|
|
|
|
2019-01-24 09:35:52 +00:00
|
|
|
CREATE INDEX transaction_id_index ON receipts (transaction_id);
|
|
|
|
|
2019-01-22 12:15:29 +00:00
|
|
|
UPDATE receipts
|
|
|
|
SET transaction_id = (
|
2019-03-19 19:11:26 +00:00
|
|
|
SELECT id FROM full_sync_transactions WHERE full_sync_transactions.hash = receipts.tx_hash
|
2019-01-22 12:15:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
ALTER TABLE receipts
|
|
|
|
ALTER COLUMN transaction_id SET NOT NULL;
|
|
|
|
|
|
|
|
ALTER TABLE receipts
|
|
|
|
ADD CONSTRAINT transaction_fk
|
|
|
|
FOREIGN KEY (transaction_id)
|
2019-03-19 19:11:26 +00:00
|
|
|
REFERENCES full_sync_transactions (id)
|
2019-01-22 12:15:29 +00:00
|
|
|
ON DELETE CASCADE;
|
|
|
|
|
|
|
|
ALTER TABLE receipts
|
|
|
|
DROP COLUMN block_id;
|