diff --git a/cmd/backfillMakerLogs.go b/cmd/backfillMakerLogs.go index 339b9252..f8856825 100644 --- a/cmd/backfillMakerLogs.go +++ b/cmd/backfillMakerLogs.go @@ -47,8 +47,9 @@ func backfillMakerLogs() { log.Fatal("Failed to initialize database.") } + repository := shared2.Repository{} fetcher := shared2.NewFetcher(blockChain) - watcher := shared.NewWatcher(db, fetcher) + watcher := shared.NewWatcher(db, fetcher, repository) watcher.AddTransformers(transformers.TransformerInitializers()) watcher.Execute() diff --git a/libraries/shared/watcher.go b/libraries/shared/watcher.go index 744eb341..a9f94d91 100644 --- a/libraries/shared/watcher.go +++ b/libraries/shared/watcher.go @@ -3,11 +3,18 @@ package shared import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/vulcanize/vulcanizedb/pkg/core" "github.com/vulcanize/vulcanizedb/pkg/datastore/postgres" "github.com/vulcanize/vulcanizedb/pkg/transformers" "github.com/vulcanize/vulcanizedb/pkg/transformers/shared" ) +type WatcherRepository interface { + GetCheckedColumnNames(db *postgres.DB) ([]string, error) + CreateNotCheckedSQL(boolColumns []string) string + MissingHeaders(startingBlockNumber int64, endingBlockNumber int64, db *postgres.DB, notCheckedSQL string) ([]core.Header, error) +} + type Watcher struct { Transformers []shared.Transformer DB *postgres.DB @@ -15,9 +22,10 @@ type Watcher struct { Chunker shared.LogChunker Addresses []common.Address Topics []common.Hash + Repository WatcherRepository } -func NewWatcher(db *postgres.DB, fetcher shared.LogFetcher) Watcher { +func NewWatcher(db *postgres.DB, fetcher shared.LogFetcher, repository WatcherRepository) Watcher { transformerConfigs := transformers.TransformerConfigs() var contractAddresses []common.Address var topic0s []common.Hash @@ -32,11 +40,12 @@ func NewWatcher(db *postgres.DB, fetcher shared.LogFetcher) Watcher { chunker := shared.NewLogChunker(transformerConfigs) return Watcher{ - DB: db, - Fetcher: fetcher, - Chunker: chunker, - Addresses: contractAddresses, - Topics: topic0s, + DB: db, + Fetcher: fetcher, + Chunker: chunker, + Addresses: contractAddresses, + Topics: topic0s, + Repository: repository, } } @@ -48,14 +57,14 @@ func (watcher *Watcher) AddTransformers(us []shared.TransformerInitializer) { } func (watcher *Watcher) Execute() error { - checkedColumnNames, err := shared.GetCheckedColumnNames(watcher.DB) + checkedColumnNames, err := watcher.Repository.GetCheckedColumnNames(watcher.DB) if err != nil { return err } - notCheckedSQL := shared.CreateNotCheckedSQL(checkedColumnNames) + notCheckedSQL := watcher.Repository.CreateNotCheckedSQL(checkedColumnNames) - // TODO Handle start and end numbers in transformers? - missingHeaders, err := shared.MissingHeaders(0, -1, watcher.DB, notCheckedSQL) + // TODO Handle start and end numbers in transformers + missingHeaders, err := watcher.Repository.MissingHeaders(0, -1, watcher.DB, notCheckedSQL) if err != nil { log.Error("Fetching of missing headers failed in watcher!") return err @@ -66,7 +75,7 @@ func (watcher *Watcher) Execute() error { logs, err := watcher.Fetcher.FetchLogs(watcher.Addresses, watcher.Topics, header) if err != nil { // TODO Handle fetch error in watcher - log.Error("Error while fetching logs in watcher") + log.Error("Error while fetching logs for header %v in watcher", header.Id) return err } @@ -76,7 +85,7 @@ func (watcher *Watcher) Execute() error { logChunk := chunkedLogs[transformer.Name()] err = transformer.Execute(logChunk, header) if err != nil { - log.Error("%v transformer failed to execute: %v", transformer.Name(), err) + log.Error("%v transformer failed to execute in watcher: %v", transformer.Name(), err) return err } } diff --git a/pkg/transformers/bite/repository.go b/pkg/transformers/bite/repository.go index 1e3d860b..290deaee 100644 --- a/pkg/transformers/bite/repository.go +++ b/pkg/transformers/bite/repository.go @@ -52,7 +52,7 @@ func (repository BiteRepository) Create(headerID int64, models []interface{}) er } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.BiteChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.BiteChecked) if err != nil { tx.Rollback() return err @@ -62,5 +62,5 @@ func (repository BiteRepository) Create(headerID int64, models []interface{}) er } func (repository BiteRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.BiteChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.BiteChecked) } diff --git a/pkg/transformers/cat_file/chop_lump/repository.go b/pkg/transformers/cat_file/chop_lump/repository.go index 9dff41f7..c63e83b6 100644 --- a/pkg/transformers/cat_file/chop_lump/repository.go +++ b/pkg/transformers/cat_file/chop_lump/repository.go @@ -49,7 +49,7 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []inte } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked) if err != nil { tx.Rollback() return err @@ -58,7 +58,7 @@ func (repository CatFileChopLumpRepository) Create(headerID int64, models []inte } func (repository CatFileChopLumpRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFileChopLumpChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.CatFileChopLumpChecked) } func (repository *CatFileChopLumpRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/cat_file/flip/repository.go b/pkg/transformers/cat_file/flip/repository.go index a07ca207..624e37d3 100644 --- a/pkg/transformers/cat_file/flip/repository.go +++ b/pkg/transformers/cat_file/flip/repository.go @@ -48,7 +48,7 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []interfac } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileFlipChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileFlipChecked) if err != nil { tx.Rollback() return err @@ -57,7 +57,7 @@ func (repository CatFileFlipRepository) Create(headerID int64, models []interfac } func (repository CatFileFlipRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFileFlipChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.CatFileFlipChecked) } func (repository *CatFileFlipRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/cat_file/pit_vow/repository.go b/pkg/transformers/cat_file/pit_vow/repository.go index 861dc2a8..8e2e3a29 100644 --- a/pkg/transformers/cat_file/pit_vow/repository.go +++ b/pkg/transformers/cat_file/pit_vow/repository.go @@ -48,7 +48,7 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []interf } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFilePitVowChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFilePitVowChecked) if err != nil { tx.Rollback() return err @@ -57,7 +57,7 @@ func (repository CatFilePitVowRepository) Create(headerID int64, models []interf } func (repository CatFilePitVowRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.CatFilePitVowChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.CatFilePitVowChecked) } func (repository *CatFilePitVowRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/deal/repository.go b/pkg/transformers/deal/repository.go index 06f23230..825f00d6 100644 --- a/pkg/transformers/deal/repository.go +++ b/pkg/transformers/deal/repository.go @@ -49,7 +49,7 @@ func (repository DealRepository) Create(headerID int64, models []interface{}) er } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DealChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.DealChecked) if err != nil { tx.Rollback() return err @@ -58,7 +58,7 @@ func (repository DealRepository) Create(headerID int64, models []interface{}) er } func (repository DealRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DealChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.DealChecked) } func (repository *DealRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/dent/repository.go b/pkg/transformers/dent/repository.go index 0ff5370b..80aee3e0 100644 --- a/pkg/transformers/dent/repository.go +++ b/pkg/transformers/dent/repository.go @@ -54,7 +54,7 @@ func (repository DentRepository) Create(headerID int64, models []interface{}) er } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DentChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.DentChecked) if err != nil { tx.Rollback() return err @@ -63,7 +63,7 @@ func (repository DentRepository) Create(headerID int64, models []interface{}) er } func (repository DentRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.DentChecked) + return shared.Repository{}.MarkHeaderChecked(headerId, repository.db, constants.DentChecked) } func (repository *DentRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/drip_drip/repository.go b/pkg/transformers/drip_drip/repository.go index edb1208a..c9fa1623 100644 --- a/pkg/transformers/drip_drip/repository.go +++ b/pkg/transformers/drip_drip/repository.go @@ -48,7 +48,7 @@ func (repository DripDripRepository) Create(headerID int64, models []interface{} } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripDripChecked) if err != nil { tx.Rollback() return err @@ -57,7 +57,7 @@ func (repository DripDripRepository) Create(headerID int64, models []interface{} } func (repository DripDripRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DripDripChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.DripDripChecked) } func (repository *DripDripRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/drip_file/ilk/repository.go b/pkg/transformers/drip_file/ilk/repository.go index 117a28fd..3740c548 100644 --- a/pkg/transformers/drip_file/ilk/repository.go +++ b/pkg/transformers/drip_file/ilk/repository.go @@ -50,7 +50,7 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileIlkChecked) if err != nil { tx.Rollback() return err @@ -60,7 +60,7 @@ func (repository DripFileIlkRepository) Create(headerID int64, models []interfac } func (repository DripFileIlkRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileIlkChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.DripFileIlkChecked) } func (repository *DripFileIlkRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/drip_file/repo/repository.go b/pkg/transformers/drip_file/repo/repository.go index dc9589a7..23d08af2 100644 --- a/pkg/transformers/drip_file/repo/repository.go +++ b/pkg/transformers/drip_file/repo/repository.go @@ -50,7 +50,7 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []interfa } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileRepoChecked) if err != nil { tx.Rollback() return err @@ -60,7 +60,7 @@ func (repository DripFileRepoRepository) Create(headerID int64, models []interfa } func (repository DripFileRepoRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileRepoChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.DripFileRepoChecked) } func (repository *DripFileRepoRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/drip_file/vow/repository.go b/pkg/transformers/drip_file/vow/repository.go index aa23bea8..86bdf8f2 100644 --- a/pkg/transformers/drip_file/vow/repository.go +++ b/pkg/transformers/drip_file/vow/repository.go @@ -49,7 +49,7 @@ func (repository DripFileVowRepository) Create(headerID int64, models []interfac } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.DripFileVowChecked) if err != nil { tx.Rollback() return err @@ -59,7 +59,7 @@ func (repository DripFileVowRepository) Create(headerID int64, models []interfac } func (repository DripFileVowRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.DripFileVowChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.DripFileVowChecked) } func (repository *DripFileVowRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/flap_kick/repository.go b/pkg/transformers/flap_kick/repository.go index f9f11c7a..950ebcb0 100644 --- a/pkg/transformers/flap_kick/repository.go +++ b/pkg/transformers/flap_kick/repository.go @@ -47,7 +47,7 @@ func (repository *FlapKickRepository) Create(headerID int64, models []interface{ } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlapKickChecked) if err != nil { tx.Rollback() return err @@ -56,7 +56,7 @@ func (repository *FlapKickRepository) Create(headerID int64, models []interface{ } func (repository *FlapKickRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.FlapKickChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.FlapKickChecked) } func (repository *FlapKickRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/flip_kick/repository.go b/pkg/transformers/flip_kick/repository.go index db8a8d01..99c376be 100644 --- a/pkg/transformers/flip_kick/repository.go +++ b/pkg/transformers/flip_kick/repository.go @@ -47,7 +47,7 @@ func (repository FlipKickRepository) Create(headerID int64, models []interface{} return err } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlipKickChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlipKickChecked) if err != nil { tx.Rollback() return err @@ -56,7 +56,7 @@ func (repository FlipKickRepository) Create(headerID int64, models []interface{} } func (repository FlipKickRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.FlipKickChecked) + return shared.Repository{}.MarkHeaderChecked(headerId, repository.db, constants.FlipKickChecked) } func (repository *FlipKickRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/flop_kick/repository.go b/pkg/transformers/flop_kick/repository.go index 7a302c75..1bab62c6 100644 --- a/pkg/transformers/flop_kick/repository.go +++ b/pkg/transformers/flop_kick/repository.go @@ -48,7 +48,7 @@ func (repository FlopKickRepository) Create(headerID int64, models []interface{} } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlopKickChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.FlopKickChecked) if err != nil { tx.Rollback() return err @@ -58,7 +58,7 @@ func (repository FlopKickRepository) Create(headerID int64, models []interface{} } func (repository FlopKickRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.FlopKickChecked) + return shared.Repository{}.MarkHeaderChecked(headerId, repository.db, constants.FlopKickChecked) } func (repository *FlopKickRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/frob/repository.go b/pkg/transformers/frob/repository.go index bf6d4d08..e2c26435 100644 --- a/pkg/transformers/frob/repository.go +++ b/pkg/transformers/frob/repository.go @@ -46,7 +46,7 @@ func (repository FrobRepository) Create(headerID int64, models []interface{}) er return err } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.FrobChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.FrobChecked) if err != nil { tx.Rollback() return err @@ -55,7 +55,7 @@ func (repository FrobRepository) Create(headerID int64, models []interface{}) er } func (repository FrobRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.FrobChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.FrobChecked) } func (repository *FrobRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/pit_file/debt_ceiling/repository.go b/pkg/transformers/pit_file/debt_ceiling/repository.go index 12f69fb2..38b648ba 100644 --- a/pkg/transformers/pit_file/debt_ceiling/repository.go +++ b/pkg/transformers/pit_file/debt_ceiling/repository.go @@ -50,7 +50,7 @@ func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []i } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileDebtCeilingChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileDebtCeilingChecked) if err != nil { tx.Rollback() return err @@ -60,7 +60,7 @@ func (repository PitFileDebtCeilingRepository) Create(headerID int64, models []i } func (repository PitFileDebtCeilingRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.PitFileDebtCeilingChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.PitFileDebtCeilingChecked) } func (repository *PitFileDebtCeilingRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/pit_file/ilk/repository.go b/pkg/transformers/pit_file/ilk/repository.go index 9a187de7..3dae51c6 100644 --- a/pkg/transformers/pit_file/ilk/repository.go +++ b/pkg/transformers/pit_file/ilk/repository.go @@ -49,7 +49,7 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileIlkChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.PitFileIlkChecked) if err != nil { tx.Rollback() return err @@ -58,7 +58,7 @@ func (repository PitFileIlkRepository) Create(headerID int64, models []interface } func (repository PitFileIlkRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.PitFileIlkChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.PitFileIlkChecked) } func (repository *PitFileIlkRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/price_feeds/repository.go b/pkg/transformers/price_feeds/repository.go index cbb9a012..af1caf19 100644 --- a/pkg/transformers/price_feeds/repository.go +++ b/pkg/transformers/price_feeds/repository.go @@ -45,7 +45,7 @@ func (repository PriceFeedRepository) Create(headerID int64, models []interface{ } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.PriceFeedsChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.PriceFeedsChecked) if err != nil { tx.Rollback() return err @@ -54,7 +54,7 @@ func (repository PriceFeedRepository) Create(headerID int64, models []interface{ } func (repository PriceFeedRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.PriceFeedsChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.PriceFeedsChecked) } func (repository *PriceFeedRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/shared/repository.go b/pkg/transformers/shared/repository.go index 0380d50a..65b4f938 100644 --- a/pkg/transformers/shared/repository.go +++ b/pkg/transformers/shared/repository.go @@ -9,7 +9,9 @@ import ( "strings" ) -func MarkHeaderChecked(headerID int64, db *postgres.DB, checkedHeadersColumn string) error { +type Repository struct{} + +func (_ Repository) MarkHeaderChecked(headerID int64, db *postgres.DB, checkedHeadersColumn string) error { _, err := db.Exec(`INSERT INTO public.checked_headers (header_id, `+checkedHeadersColumn+`) VALUES ($1, $2) ON CONFLICT (header_id) DO @@ -17,7 +19,7 @@ func MarkHeaderChecked(headerID int64, db *postgres.DB, checkedHeadersColumn str return err } -func MarkHeaderCheckedInTransaction(headerID int64, tx *sql.Tx, checkedHeadersColumn string) error { +func (_ Repository) MarkHeaderCheckedInTransaction(headerID int64, tx *sql.Tx, checkedHeadersColumn string) error { _, err := tx.Exec(`INSERT INTO public.checked_headers (header_id, `+checkedHeadersColumn+`) VALUES ($1, $2) ON CONFLICT (header_id) DO @@ -26,7 +28,7 @@ func MarkHeaderCheckedInTransaction(headerID int64, tx *sql.Tx, checkedHeadersCo } // Treats a header as missing if it's not in the headers table, or not checked for some log type -func MissingHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.DB, notCheckedSQL string) ([]core.Header, error) { +func (_ Repository) MissingHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.DB, notCheckedSQL string) ([]core.Header, error) { var result []core.Header var query string var err error @@ -51,7 +53,7 @@ func MissingHeaders(startingBlockNumber, endingBlockNumber int64, db *postgres.D return result, err } -func GetCheckedColumnNames(db *postgres.DB) ([]string, error) { +func (_ Repository) GetCheckedColumnNames(db *postgres.DB) ([]string, error) { // Query returns `[]driver.Value`, nullable polymorphic interface var queryResult []driver.Value columnNamesQuery := @@ -83,7 +85,7 @@ func GetCheckedColumnNames(db *postgres.DB) ([]string, error) { // Defaults to FALSE when no columns are provided. // Ex: ["columnA", "columnB"] => "NOT (columnA AND columnB)" // [] => "FALSE" -func CreateNotCheckedSQL(boolColumns []string) string { +func (_ Repository) CreateNotCheckedSQL(boolColumns []string) string { var result strings.Builder if len(boolColumns) == 0 { diff --git a/pkg/transformers/shared/repository_utility_test.go b/pkg/transformers/shared/repository_utility_test.go index b5a290aa..b24cde03 100644 --- a/pkg/transformers/shared/repository_utility_test.go +++ b/pkg/transformers/shared/repository_utility_test.go @@ -27,7 +27,7 @@ var _ = Describe("Repository utilities", func() { db := test_config.NewTestDB(test_config.NewTestNode()) test_config.CleanTestDB(db) expectedColumnNames := getExpectedColumnNames() - actualColumnNames, err := shared.GetCheckedColumnNames(db) + actualColumnNames, err := shared.Repository{}.GetCheckedColumnNames(db) Expect(err).NotTo(HaveOccurred()) Expect(actualColumnNames).To(Equal(expectedColumnNames)) }) @@ -37,20 +37,20 @@ var _ = Describe("Repository utilities", func() { It("generates a correct SQL string for one column", func() { columns := []string{"columnA"} expected := "NOT (columnA)" - actual := shared.CreateNotCheckedSQL(columns) + actual := shared.Repository{}.CreateNotCheckedSQL(columns) Expect(actual).To(Equal(expected)) }) It("generates a correct SQL string for several columns", func() { columns := []string{"columnA", "columnB"} expected := "NOT (columnA AND columnB)" - actual := shared.CreateNotCheckedSQL(columns) + actual := shared.Repository{}.CreateNotCheckedSQL(columns) Expect(actual).To(Equal(expected)) }) It("defaults to FALSE when there are no columns", func() { expected := "FALSE" - actual := shared.CreateNotCheckedSQL([]string{}) + actual := shared.Repository{}.CreateNotCheckedSQL([]string{}) Expect(actual).To(Equal(expected)) }) }) diff --git a/pkg/transformers/tend/repository.go b/pkg/transformers/tend/repository.go index 17620a00..bfabd248 100644 --- a/pkg/transformers/tend/repository.go +++ b/pkg/transformers/tend/repository.go @@ -55,7 +55,7 @@ func (repository TendRepository) Create(headerID int64, models []interface{}) er } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.TendChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.TendChecked) if err != nil { tx.Rollback() return err @@ -64,7 +64,7 @@ func (repository TendRepository) Create(headerID int64, models []interface{}) er } func (repository TendRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.TendChecked) + return shared.Repository{}.MarkHeaderChecked(headerId, repository.db, constants.TendChecked) } func (repository *TendRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_flux/repository.go b/pkg/transformers/vat_flux/repository.go index 2febe527..78089701 100644 --- a/pkg/transformers/vat_flux/repository.go +++ b/pkg/transformers/vat_flux/repository.go @@ -47,7 +47,7 @@ func (repository VatFluxRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFluxChecked) if err != nil { tx.Rollback() return err @@ -57,7 +57,7 @@ func (repository VatFluxRepository) Create(headerID int64, models []interface{}) } func (repository VatFluxRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.VatFluxChecked) + return shared.Repository{}.MarkHeaderChecked(headerId, repository.db, constants.VatFluxChecked) } func (repository *VatFluxRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_fold/repository.go b/pkg/transformers/vat_fold/repository.go index 5d831bca..01ba28ba 100644 --- a/pkg/transformers/vat_fold/repository.go +++ b/pkg/transformers/vat_fold/repository.go @@ -49,7 +49,7 @@ func (repository VatFoldRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatFoldChecked) if err != nil { tx.Rollback() return err @@ -59,7 +59,7 @@ func (repository VatFoldRepository) Create(headerID int64, models []interface{}) } func (repository VatFoldRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatFoldChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatFoldChecked) } func (repository *VatFoldRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_grab/repository.go b/pkg/transformers/vat_grab/repository.go index a8a274a4..14364b90 100644 --- a/pkg/transformers/vat_grab/repository.go +++ b/pkg/transformers/vat_grab/repository.go @@ -34,7 +34,7 @@ func (repository VatGrabRepository) Create(headerID int64, models []interface{}) return err } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatGrabChecked) if err != nil { tx.Rollback() return err @@ -43,7 +43,7 @@ func (repository VatGrabRepository) Create(headerID int64, models []interface{}) } func (repository VatGrabRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatGrabChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatGrabChecked) } func (repository *VatGrabRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_heal/repository.go b/pkg/transformers/vat_heal/repository.go index aed8fcd0..861025a6 100644 --- a/pkg/transformers/vat_heal/repository.go +++ b/pkg/transformers/vat_heal/repository.go @@ -52,7 +52,7 @@ func (repository VatHealRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatHealChecked) if err != nil { tx.Rollback() return err @@ -61,5 +61,5 @@ func (repository VatHealRepository) Create(headerID int64, models []interface{}) } func (repository VatHealRepository) MarkHeaderChecked(headerId int64) error { - return shared.MarkHeaderChecked(headerId, repository.db, constants.VatHealChecked) + return shared.Repository{}.MarkHeaderChecked(headerId, repository.db, constants.VatHealChecked) } diff --git a/pkg/transformers/vat_init/repository.go b/pkg/transformers/vat_init/repository.go index 14b2d4c8..1bb56d12 100644 --- a/pkg/transformers/vat_init/repository.go +++ b/pkg/transformers/vat_init/repository.go @@ -49,7 +49,7 @@ func (repository VatInitRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatInitChecked) if err != nil { tx.Rollback() return err @@ -59,7 +59,7 @@ func (repository VatInitRepository) Create(headerID int64, models []interface{}) } func (repository VatInitRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatInitChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatInitChecked) } func (repository *VatInitRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_move/repository.go b/pkg/transformers/vat_move/repository.go index 2548c2b4..913b587c 100644 --- a/pkg/transformers/vat_move/repository.go +++ b/pkg/transformers/vat_move/repository.go @@ -50,7 +50,7 @@ func (repository VatMoveRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatMoveChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatMoveChecked) if err != nil { tx.Rollback() return err @@ -60,7 +60,7 @@ func (repository VatMoveRepository) Create(headerID int64, models []interface{}) } func (repository VatMoveRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatMoveChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatMoveChecked) } func (repository *VatMoveRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_slip/repository.go b/pkg/transformers/vat_slip/repository.go index 15f412ca..b84f248c 100644 --- a/pkg/transformers/vat_slip/repository.go +++ b/pkg/transformers/vat_slip/repository.go @@ -34,7 +34,7 @@ func (repository VatSlipRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatSlipChecked) if err != nil { tx.Rollback() return err @@ -44,7 +44,7 @@ func (repository VatSlipRepository) Create(headerID int64, models []interface{}) } func (repository VatSlipRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatSlipChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatSlipChecked) } func (repository *VatSlipRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_toll/repository.go b/pkg/transformers/vat_toll/repository.go index 2c9be8a4..6c738e54 100644 --- a/pkg/transformers/vat_toll/repository.go +++ b/pkg/transformers/vat_toll/repository.go @@ -34,7 +34,7 @@ func (repository VatTollRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTollChecked) if err != nil { tx.Rollback() return err @@ -43,7 +43,7 @@ func (repository VatTollRepository) Create(headerID int64, models []interface{}) } func (repository VatTollRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatTollChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatTollChecked) } func (repository *VatTollRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vat_tune/repository.go b/pkg/transformers/vat_tune/repository.go index c9951ce6..79404cb0 100644 --- a/pkg/transformers/vat_tune/repository.go +++ b/pkg/transformers/vat_tune/repository.go @@ -34,7 +34,7 @@ func (repository VatTuneRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VatTuneChecked) if err != nil { tx.Rollback() return err @@ -43,7 +43,7 @@ func (repository VatTuneRepository) Create(headerID int64, models []interface{}) } func (repository VatTuneRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VatTuneChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VatTuneChecked) } func (repository *VatTuneRepository) SetDB(db *postgres.DB) { diff --git a/pkg/transformers/vow_flog/repository.go b/pkg/transformers/vow_flog/repository.go index 48076802..994de3e2 100644 --- a/pkg/transformers/vow_flog/repository.go +++ b/pkg/transformers/vow_flog/repository.go @@ -50,7 +50,7 @@ func (repository VowFlogRepository) Create(headerID int64, models []interface{}) } } - err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.VowFlogChecked) + err = shared.Repository{}.MarkHeaderCheckedInTransaction(headerID, tx, constants.VowFlogChecked) if err != nil { tx.Rollback() return err @@ -60,7 +60,7 @@ func (repository VowFlogRepository) Create(headerID int64, models []interface{}) } func (repository VowFlogRepository) MarkHeaderChecked(headerID int64) error { - return shared.MarkHeaderChecked(headerID, repository.db, constants.VowFlogChecked) + return shared.Repository{}.MarkHeaderChecked(headerID, repository.db, constants.VowFlogChecked) } func (repository *VowFlogRepository) SetDB(db *postgres.DB) {