diff --git a/db/migrations/1516050071_add_log_fk_constraint.down.sql b/db/migrations/1516050071_add_log_fk_constraint.down.sql index 6ce8446f..55779b51 100644 --- a/db/migrations/1516050071_add_log_fk_constraint.down.sql +++ b/db/migrations/1516050071_add_log_fk_constraint.down.sql @@ -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; \ No newline at end of file diff --git a/db/migrations/1516050071_add_log_fk_constraint.up.sql b/db/migrations/1516050071_add_log_fk_constraint.up.sql index a0150d1a..60733b71 100644 --- a/db/migrations/1516050071_add_log_fk_constraint.up.sql +++ b/db/migrations/1516050071_add_log_fk_constraint.up.sql @@ -1,4 +1,6 @@ BEGIN; +ALTER TABLE logs + DROP CONSTRAINT log_uc; ALTER TABLE logs ADD COLUMN receipt_id INT; diff --git a/db/schema.sql b/db/schema.sql index 0b7f6190..e2e1ece3 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -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: - -- diff --git a/pkg/repositories/postgres.go b/pkg/repositories/postgres.go index ef63d396..14159547 100644 --- a/pkg/repositories/postgres.go +++ b/pkg/repositories/postgres.go @@ -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, ) diff --git a/pkg/repositories/testing/helpers.go b/pkg/repositories/testing/helpers.go index 6a89fd29..899b0987 100644 --- a/pkg/repositories/testing/helpers.go +++ b/pkg/repositories/testing/helpers.go @@ -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,