diff --git a/db/migrations/1534295713_create_bite_table.up.sql b/db/migrations/1534295713_create_bite_table.up.sql index eb32e324..5cc7041f 100644 --- a/db/migrations/1534295713_create_bite_table.up.sql +++ b/db/migrations/1534295713_create_bite_table.up.sql @@ -9,5 +9,6 @@ CREATE TABLE maker.bite ( tab NUMERIC, flip VARCHAR, tx_idx INTEGER NOT NUll, - raw_log JSONB + raw_log JSONB, + UNIQUE (header_id, tx_idx) ) \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 9d1bc2b0..25cd7541 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -701,6 +701,14 @@ ALTER TABLE ONLY public.transactions ALTER COLUMN id SET DEFAULT nextval('public ALTER TABLE ONLY public.watched_contracts ALTER COLUMN contract_id SET DEFAULT nextval('public.watched_contracts_contract_id_seq'::regclass); +-- +-- Name: bite bite_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.bite + ADD CONSTRAINT bite_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + + -- -- Name: bite bite_pkey; Type: CONSTRAINT; Schema: maker; Owner: - -- diff --git a/pkg/transformers/bite/converter.go b/pkg/transformers/bite/converter.go index 27ef56d3..558a5553 100644 --- a/pkg/transformers/bite/converter.go +++ b/pkg/transformers/bite/converter.go @@ -48,6 +48,7 @@ func (BiteConverter) ToEntity(contractAddress string, contractAbi string, ethLog } entity.Raw = ethLog + entity.TransactionIndex = ethLog.TxIndex return entity, nil } diff --git a/pkg/transformers/bite/converter_test.go b/pkg/transformers/bite/converter_test.go index 79a11168..129e93e3 100644 --- a/pkg/transformers/bite/converter_test.go +++ b/pkg/transformers/bite/converter_test.go @@ -17,14 +17,15 @@ package bite_test import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - + "math/big" "encoding/json" + "github.com/ethereum/go-ethereum/core/types" "github.com/vulcanize/vulcanizedb/pkg/transformers/bite" "github.com/vulcanize/vulcanizedb/pkg/transformers/test_data" - "math/big" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) var _ = Describe("Bite Converter", func() { @@ -42,6 +43,8 @@ var _ = Describe("Bite Converter", func() { Expect(entity.Tab).To(Equal(test_data.BiteEntity.Tab)) Expect(entity.Flip).To(Equal(test_data.BiteEntity.Flip)) Expect(entity.IArt).To(Equal(test_data.BiteEntity.IArt)) + Expect(entity.TransactionIndex).To(Equal(test_data.BiteEntity.TransactionIndex)) + Expect(entity.Raw).To(Equal(test_data.BiteEntity.Raw)) }) It("returns an error if converting log to entity fails", func() { @@ -63,10 +66,10 @@ var _ = Describe("Bite Converter", func() { Expect(err).NotTo(HaveOccurred()) Expect(model).To(Equal(test_data.BiteModel)) + Expect(model.TransactionIndex).To(Equal(test_data.BiteModel.TransactionIndex)) }) It("handles nil values", func() { - emptyEntity.Id = big.NewInt(1) emptyLog, err := json.Marshal(types.Log{}) Expect(err).NotTo(HaveOccurred()) expectedModel := bite.BiteModel{ diff --git a/pkg/transformers/bite/repository_test.go b/pkg/transformers/bite/repository_test.go index 60c88160..8e89e3ec 100644 --- a/pkg/transformers/bite/repository_test.go +++ b/pkg/transformers/bite/repository_test.go @@ -64,7 +64,20 @@ var _ = Describe("Bite repository", func() { err = biteRepository.Create(headerID, test_data.BiteModel) Expect(err).NotTo(HaveOccurred()) - err = biteRepository.Create(headerID, test_data.BiteModel) + var anotherBiteModel = bite.BiteModel{ + Id: "11", + Ilk: test_data.BiteModel.Ilk, + Lad: test_data.BiteModel.Lad, + Ink: test_data.BiteModel.Ink, + Art: test_data.BiteModel.Art, + Tab: test_data.BiteModel.Tab, + Flip: test_data.BiteModel.Flip, + IArt: test_data.BiteModel.IArt, + TransactionIndex: test_data.BiteModel.TransactionIndex, + Raw: test_data.BiteModel.Raw, + } + + err = biteRepository.Create(headerID, anotherBiteModel) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("pq: duplicate key value violates unique constraint"))