2021-01-21 09:49:38 +00:00
|
|
|
package eventstore
|
|
|
|
|
|
|
|
type EventUniqueConstraint 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
|
2022-05-16 09:52:54 +00:00
|
|
|
//IsGlobal defines if the unique constraint is globally unique or just within a single instance
|
|
|
|
IsGlobal bool
|
2021-01-21 09:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type UniqueConstraintAction int32
|
|
|
|
|
|
|
|
const (
|
|
|
|
UniqueConstraintAdd UniqueConstraintAction = iota
|
|
|
|
UniqueConstraintRemove
|
2022-10-26 13:06:48 +00:00
|
|
|
UniqueConstraintInstanceRemove
|
2021-01-21 09:49:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewAddEventUniqueConstraint(
|
|
|
|
uniqueType,
|
|
|
|
uniqueField,
|
|
|
|
errMessage string) *EventUniqueConstraint {
|
|
|
|
return &EventUniqueConstraint{
|
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
ErrorMessage: errMessage,
|
|
|
|
Action: UniqueConstraintAdd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemoveEventUniqueConstraint(
|
|
|
|
uniqueType,
|
|
|
|
uniqueField string) *EventUniqueConstraint {
|
|
|
|
return &EventUniqueConstraint{
|
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
Action: UniqueConstraintRemove,
|
|
|
|
}
|
|
|
|
}
|
2022-05-16 09:52:54 +00:00
|
|
|
|
2022-10-26 13:06:48 +00:00
|
|
|
func NewRemoveInstanceUniqueConstraints() *EventUniqueConstraint {
|
|
|
|
return &EventUniqueConstraint{
|
|
|
|
Action: UniqueConstraintInstanceRemove,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 09:52:54 +00:00
|
|
|
func NewAddGlobalEventUniqueConstraint(
|
|
|
|
uniqueType,
|
|
|
|
uniqueField,
|
|
|
|
errMessage string) *EventUniqueConstraint {
|
|
|
|
return &EventUniqueConstraint{
|
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
ErrorMessage: errMessage,
|
|
|
|
IsGlobal: true,
|
|
|
|
Action: UniqueConstraintAdd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRemoveGlobalEventUniqueConstraint(
|
|
|
|
uniqueType,
|
|
|
|
uniqueField string) *EventUniqueConstraint {
|
|
|
|
return &EventUniqueConstraint{
|
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
IsGlobal: true,
|
|
|
|
Action: UniqueConstraintRemove,
|
|
|
|
}
|
|
|
|
}
|