mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
refactor(v2): init eventstore package (#7806)
* refactor(v2): init database package * refactor(v2): init eventstore package * add mock package * test query constructors * option based push analog to query
This commit is contained in:
80
internal/v2/eventstore/unique_constraint.go
Normal file
80
internal/v2/eventstore/unique_constraint.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package eventstore
|
||||
|
||||
type UniqueConstraint struct {
|
||||
// UniqueType is the table name for the unique constraint
|
||||
UniqueType string
|
||||
// UniqueField is the unique key
|
||||
UniqueField string
|
||||
// Action defines if unique constraint should be added or removed
|
||||
Action UniqueConstraintAction
|
||||
// ErrorMessage defines the translation file key for the error message
|
||||
ErrorMessage string
|
||||
// IsGlobal defines if the unique constraint is globally unique or just within a single instance
|
||||
IsGlobal bool
|
||||
}
|
||||
|
||||
type UniqueConstraintAction int8
|
||||
|
||||
const (
|
||||
UniqueConstraintAdd UniqueConstraintAction = iota
|
||||
UniqueConstraintRemove
|
||||
UniqueConstraintInstanceRemove
|
||||
|
||||
uniqueConstraintActionCount
|
||||
)
|
||||
|
||||
func (f UniqueConstraintAction) Valid() bool {
|
||||
return f >= 0 && f < uniqueConstraintActionCount
|
||||
}
|
||||
|
||||
func NewAddEventUniqueConstraint(
|
||||
uniqueType,
|
||||
uniqueField,
|
||||
errMessage string) *UniqueConstraint {
|
||||
return &UniqueConstraint{
|
||||
UniqueType: uniqueType,
|
||||
UniqueField: uniqueField,
|
||||
ErrorMessage: errMessage,
|
||||
Action: UniqueConstraintAdd,
|
||||
}
|
||||
}
|
||||
|
||||
func NewRemoveUniqueConstraint(
|
||||
uniqueType,
|
||||
uniqueField string) *UniqueConstraint {
|
||||
return &UniqueConstraint{
|
||||
UniqueType: uniqueType,
|
||||
UniqueField: uniqueField,
|
||||
Action: UniqueConstraintRemove,
|
||||
}
|
||||
}
|
||||
|
||||
func NewRemoveInstanceUniqueConstraints() *UniqueConstraint {
|
||||
return &UniqueConstraint{
|
||||
Action: UniqueConstraintInstanceRemove,
|
||||
}
|
||||
}
|
||||
|
||||
func NewAddGlobalUniqueConstraint(
|
||||
uniqueType,
|
||||
uniqueField,
|
||||
errMessage string) *UniqueConstraint {
|
||||
return &UniqueConstraint{
|
||||
UniqueType: uniqueType,
|
||||
UniqueField: uniqueField,
|
||||
ErrorMessage: errMessage,
|
||||
IsGlobal: true,
|
||||
Action: UniqueConstraintAdd,
|
||||
}
|
||||
}
|
||||
|
||||
func NewRemoveGlobalUniqueConstraint(
|
||||
uniqueType,
|
||||
uniqueField string) *UniqueConstraint {
|
||||
return &UniqueConstraint{
|
||||
UniqueType: uniqueType,
|
||||
UniqueField: uniqueField,
|
||||
IsGlobal: true,
|
||||
Action: UniqueConstraintRemove,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user