From 996564f956a6c78c27bf7a6119ca650d90ebd8ec Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Thu, 11 Jun 2020 16:49:50 -0400 Subject: [PATCH] Tweak base store constructors to be more restrictive --- storage/boltz/crud_test.go | 4 ++-- storage/boltz/migration.go | 2 +- storage/boltz/query_test.go | 4 ++-- storage/boltz/store.go | 10 +++++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/storage/boltz/crud_test.go b/storage/boltz/crud_test.go index 3efb8c1c..ca5add5c 100644 --- a/storage/boltz/crud_test.go +++ b/storage/boltz/crud_test.go @@ -79,7 +79,7 @@ func (entity *Employee) GetEntityType() string { func newEmployeeStore() *employeeStoreImpl { store := &employeeStoreImpl{ - BaseStore: NewBaseStore(nil, entityTypeEmployee, func(id string) error { + BaseStore: NewBaseStore(entityTypeEmployee, func(id string) error { return errors.Errorf("entity of type %v with id %v not found", entityTypeEmployee, id) }, "stores"), } @@ -154,7 +154,7 @@ func (entity *Location) GetEntityType() string { func newLocationStore() *locationStoreImpl { store := &locationStoreImpl{ - BaseStore: NewBaseStore(nil, entityTypeLocation, func(id string) error { + BaseStore: NewBaseStore(entityTypeLocation, func(id string) error { return errors.Errorf("entity of type %v with id %v not found", entityTypeLocation, id) }, "stores"), } diff --git a/storage/boltz/migration.go b/storage/boltz/migration.go index 4ad14327..97486049 100644 --- a/storage/boltz/migration.go +++ b/storage/boltz/migration.go @@ -48,7 +48,7 @@ func (m *migrationManager) Migrate(component string, targetVersion int, migrator version = int(*versionP) } - if version != targetVersion { + if versionP != nil && version != targetVersion { if err := m.db.Snapshot(tx); err != nil { return fmt.Errorf("failed to create bolt db snapshot: %w", err) } diff --git a/storage/boltz/query_test.go b/storage/boltz/query_test.go index 348506bd..0357729a 100644 --- a/storage/boltz/query_test.go +++ b/storage/boltz/query_test.go @@ -164,12 +164,12 @@ func (test *boltTest) createTestSchema() { } func (test *boltTest) setupScanEntity() { - test.placesStore = NewBaseStore(nil, "places", nil, "application") + test.placesStore = NewBaseStore("places", nil, "application") test.placesStore.AddIdSymbol("id", ast.NodeTypeString) test.placesStore.AddSymbol("name", ast.NodeTypeString) test.placesStore.AddSetSymbol("businesses", ast.NodeTypeString) - test.peopleStore = NewBaseStore(nil, "people", nil, "application") + test.peopleStore = NewBaseStore("people", nil, "application") test.peopleStore.AddIdSymbol("id", ast.NodeTypeString) test.peopleStore.AddSymbolWithKey("personAge", ast.NodeTypeInt64, "age") test.peopleStore.AddSymbolWithKey("index", ast.NodeTypeInt64, "index32") diff --git a/storage/boltz/store.go b/storage/boltz/store.go index 5be31165..b7914f8c 100644 --- a/storage/boltz/store.go +++ b/storage/boltz/store.go @@ -22,7 +22,15 @@ import ( "strings" ) -func NewBaseStore(parent CrudStore, entityType string, entityNotFoundF func(id string) error, basePath ...string) *BaseStore { +func NewBaseStore(entityType string, entityNotFoundF func(id string) error, basePath ...string) *BaseStore { + return newBaseStore(nil, entityType, entityNotFoundF, basePath...) +} + +func NewChildBaseStore(parent CrudStore, entityNotFoundF func(id string) error, basePath ...string) *BaseStore { + return newBaseStore(parent, parent.GetEntityType(), entityNotFoundF, basePath...) +} + +func newBaseStore(parent CrudStore, entityType string, entityNotFoundF func(id string) error, basePath ...string) *BaseStore { entityPath := append([]string{}, basePath...) if parent == nil { entityPath = append(entityPath, entityType)