-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a combined builder pattern for relationship SQL construction
This moves the behavior out of Spanner datastore and into a common lib where possible
- Loading branch information
1 parent
842a360
commit 0f37897
Showing
15 changed files
with
685 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package common | ||
|
||
import ( | ||
sq "github.com/Masterminds/squirrel" | ||
|
||
"github.com/authzed/spicedb/pkg/spiceerrors" | ||
) | ||
|
||
// SchemaInformation holds the schema information from the SQL datastore implementation. | ||
// | ||
//go:generate go run github.com/ecordell/optgen -output schema_options.go . SchemaInformation | ||
type SchemaInformation struct { | ||
RelationshipTableName string `debugmap:"visible"` | ||
|
||
ColNamespace string `debugmap:"visible"` | ||
ColObjectID string `debugmap:"visible"` | ||
ColRelation string `debugmap:"visible"` | ||
ColUsersetNamespace string `debugmap:"visible"` | ||
ColUsersetObjectID string `debugmap:"visible"` | ||
ColUsersetRelation string `debugmap:"visible"` | ||
ColCaveatName string `debugmap:"visible"` | ||
ColCaveatContext string `debugmap:"visible"` | ||
ColExpiration string `debugmap:"visible"` | ||
|
||
ColIntegrityKeyID string `debugmap:"visible"` | ||
ColIntegrityHash string `debugmap:"visible"` | ||
ColIntegrityTimestamp string `debugmap:"visible"` | ||
|
||
// PaginationFilterType is the type of pagination filter to use for this schema. | ||
PaginationFilterType PaginationFilterType `debugmap:"visible"` | ||
|
||
// PlaceholderFormat is the format of placeholders to use for this schema. | ||
PlaceholderFormat sq.PlaceholderFormat `debugmap:"visible"` | ||
|
||
// NowFunction is the function to use to get the current time in the datastore. | ||
NowFunction string `debugmap:"visible"` | ||
|
||
// ColumnOptimization is the optimization to use for columns in the schema, if any. | ||
ColumnOptimization ColumnOptimizationOption `debugmap:"visible"` | ||
|
||
// WithIntegrityColumns is a flag to indicate if the schema has integrity columns. | ||
WithIntegrityColumns bool `debugmap:"visible"` | ||
} | ||
|
||
func (si SchemaInformation) debugValidate() { | ||
spiceerrors.DebugAssert(func() bool { | ||
si.mustValidate() | ||
return true | ||
}, "SchemaInformation failed to validate") | ||
} | ||
|
||
func (si SchemaInformation) mustValidate() { | ||
if si.RelationshipTableName == "" { | ||
panic("RelationshipTableName is required") | ||
} | ||
|
||
if si.ColNamespace == "" { | ||
panic("ColNamespace is required") | ||
} | ||
|
||
if si.ColObjectID == "" { | ||
panic("ColObjectID is required") | ||
} | ||
|
||
if si.ColRelation == "" { | ||
panic("ColRelation is required") | ||
} | ||
|
||
if si.ColUsersetNamespace == "" { | ||
panic("ColUsersetNamespace is required") | ||
} | ||
|
||
if si.ColUsersetObjectID == "" { | ||
panic("ColUsersetObjectID is required") | ||
} | ||
|
||
if si.ColUsersetRelation == "" { | ||
panic("ColUsersetRelation is required") | ||
} | ||
|
||
if si.ColCaveatName == "" { | ||
panic("ColCaveatName is required") | ||
} | ||
|
||
if si.ColCaveatContext == "" { | ||
panic("ColCaveatContext is required") | ||
} | ||
|
||
if si.ColExpiration == "" { | ||
panic("ColExpiration is required") | ||
} | ||
|
||
if si.WithIntegrityColumns { | ||
if si.ColIntegrityKeyID == "" { | ||
panic("ColIntegrityKeyID is required") | ||
} | ||
|
||
if si.ColIntegrityHash == "" { | ||
panic("ColIntegrityHash is required") | ||
} | ||
|
||
if si.ColIntegrityTimestamp == "" { | ||
panic("ColIntegrityTimestamp is required") | ||
} | ||
} | ||
|
||
if si.NowFunction == "" { | ||
panic("NowFunction is required") | ||
} | ||
|
||
if si.ColumnOptimization == ColumnOptimizationOptionUnknown { | ||
panic("ColumnOptimization is required") | ||
} | ||
|
||
if si.PaginationFilterType == PaginationFilterTypeUnknown { | ||
panic("PaginationFilterType is required") | ||
} | ||
|
||
if si.PlaceholderFormat == nil { | ||
panic("PlaceholderFormat is required") | ||
} | ||
} |
Oops, something went wrong.