(VDB-380) Create separate table for ilks

- reference ilk by foreign key every place it's used
This commit is contained in:
Rob Mulholand
2019-02-21 11:23:00 -06:00
parent a27aaa7e68
commit dbdd16d3a2
64 changed files with 885 additions and 149 deletions
+10 -1
View File
@@ -30,10 +30,19 @@ func (repository VatTollRepository) Create(headerID int64, models []interface{})
return fmt.Errorf("model of type %T, not %T", model, VatTollModel{})
}
ilkID, ilkErr := shared.GetOrCreateIlkInTransaction(vatToll.Ilk, tx)
if ilkErr != nil {
rollbackErr := tx.Rollback()
if rollbackErr != nil {
log.Error("failed to rollback ", rollbackErr)
}
return ilkErr
}
_, execErr := tx.Exec(
`INSERT into maker.vat_toll (header_id, ilk, urn, take, tx_idx, log_idx, raw_log)
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
headerID, vatToll.Ilk, vatToll.Urn, vatToll.Take, vatToll.TransactionIndex, vatToll.LogIndex, vatToll.Raw,
headerID, ilkID, vatToll.Urn, vatToll.Take, vatToll.TransactionIndex, vatToll.LogIndex, vatToll.Raw,
)
if execErr != nil {
rollbackErr := tx.Rollback()
+5 -1
View File
@@ -1,8 +1,10 @@
package vat_toll_test
import (
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
"github.com/vulcanize/vulcanizedb/pkg/transformers/test_data/shared_behaviors"
"strconv"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -51,7 +53,9 @@ var _ = Describe("Vat toll repository", func() {
var dbVatToll vat_toll.VatTollModel
err = db.Get(&dbVatToll, `SELECT ilk, urn, take, tx_idx, log_idx, raw_log FROM maker.vat_toll WHERE header_id = $1`, headerID)
Expect(err).NotTo(HaveOccurred())
Expect(dbVatToll.Ilk).To(Equal(test_data.VatTollModel.Ilk))
ilkID, err := shared.GetOrCreateIlk(test_data.VatTollModel.Ilk, db)
Expect(err).NotTo(HaveOccurred())
Expect(dbVatToll.Ilk).To(Equal(strconv.Itoa(ilkID)))
Expect(dbVatToll.Urn).To(Equal(test_data.VatTollModel.Urn))
Expect(dbVatToll.Take).To(Equal(test_data.VatTollModel.Take))
Expect(dbVatToll.TransactionIndex).To(Equal(test_data.VatTollModel.TransactionIndex))