zitadel/internal/eventstore/unique_constraint.go

81 lines
1.9 KiB
Go
Raw Normal View History

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
2022-10-26 15:06:48 +02:00
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{
2022-10-26 15:06:48 +02:00
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,
}
}