Remove log_uc

* Logs now are attached to receipt, so removing block + index unique
constraint
This commit is contained in:
Matt Krump 2018-01-16 09:28:19 -06:00
parent 08993cc6a4
commit 6583ce72b8
5 changed files with 8 additions and 57 deletions

View File

@ -6,4 +6,7 @@ ALTER TABLE logs
ALTER TABLE logs
DROP COLUMN receipt_id;
ALTER TABLE logs
ADD CONSTRAINT log_uc UNIQUE (block_number, index);
COMMIT;

View File

@ -1,4 +1,6 @@
BEGIN;
ALTER TABLE logs
DROP CONSTRAINT log_uc;
ALTER TABLE logs
ADD COLUMN receipt_id INT;

View File

@ -324,14 +324,6 @@ ALTER TABLE ONLY watched_contracts
ADD CONSTRAINT contract_hash_uc UNIQUE (contract_hash);
--
-- Name: logs log_uc; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY logs
ADD CONSTRAINT log_uc UNIQUE (block_number, index);
--
-- Name: logs logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

View File

@ -351,21 +351,10 @@ func (repository Postgres) createReceipt(tx *sql.Tx, transactionId int, receipt
func (repository Postgres) createLogs(tx *sql.Tx, logs []core.Log, receiptId int) error {
for _, tlog := range logs {
_, err := tx.Exec(
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT (index, block_number)
DO UPDATE
SET block_number = $1,
address = $2,
tx_hash = $3,
index = $4,
topic0 = $5,
topic1 = $6,
topic2 = $7,
topic3 = $8,
data = $9
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data, receipt_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
`,
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data,
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data, receiptId,
)
if err != nil {
return ErrDBInsertFailed
@ -380,17 +369,6 @@ func (repository Postgres) CreateLogs(logs []core.Log) error {
_, err := tx.Exec(
`INSERT INTO logs (block_number, address, tx_hash, index, topic0, topic1, topic2, topic3, data)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
ON CONFLICT (index, block_number)
DO UPDATE
SET block_number = $1,
address = $2,
tx_hash = $3,
index = $4,
topic0 = $5,
topic1 = $6,
topic2 = $7,
topic3 = $8,
data = $9
`,
tlog.BlockNumber, tlog.Address, tlog.TxHash, tlog.Index, tlog.Topics[0], tlog.Topics[1], tlog.Topics[2], tlog.Topics[3], tlog.Data,
)

View File

@ -422,30 +422,6 @@ func AssertRepositoryBehavior(buildRepository func(node core.Node) repositories.
Expect(log).To(BeNil())
})
It("updates the log when log with when log with same block number and index is already present", func() {
repository.CreateLogs([]core.Log{{
BlockNumber: 1,
Index: 0,
Address: "x123",
TxHash: "x456",
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
Data: "xABC",
},
})
repository.CreateLogs([]core.Log{{
BlockNumber: 1,
Index: 0,
Address: "x123",
TxHash: "x456",
Topics: core.Topics{0: "x777", 1: "x888", 2: "x999"},
Data: "xXYZ",
},
})
log := repository.FindLogs("x123", 1)
Expect(log[0].Data).To(Equal("xXYZ"))
})
It("filters to the correct block number and address", func() {
repository.CreateLogs([]core.Log{{
BlockNumber: 1,