Skip to content

Commit

Permalink
Merge pull request #87 from openziti/base-store-create-tweaks
Browse files Browse the repository at this point in the history
Tweak base store constructors to be more restrictive
  • Loading branch information
plorenz committed Jun 12, 2020
2 parents bd73d96 + 996564f commit d782084
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions storage/boltz/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down Expand Up @@ -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"),
}
Expand Down
2 changes: 1 addition & 1 deletion storage/boltz/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions storage/boltz/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 9 additions & 1 deletion storage/boltz/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d782084

Please sign in to comment.