2021-01-21 09:49:38 +00:00
|
|
|
package eventstore
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
type UniqueConstraint struct {
|
2021-01-21 09:49:38 +00:00
|
|
|
// UniqueType is the table name for the unique constraint
|
|
|
|
UniqueType string
|
2023-10-19 10:19:10 +00:00
|
|
|
// UniqueField is the unique key
|
2021-01-21 09:49:38 +00:00
|
|
|
UniqueField string
|
2023-10-19 10:19:10 +00:00
|
|
|
// Action defines if unique constraint should be added or removed
|
2021-01-21 09:49:38 +00:00
|
|
|
Action UniqueConstraintAction
|
2023-10-19 10:19:10 +00:00
|
|
|
// ErrorMessage defines the translation file key for the error message
|
2021-01-21 09:49:38 +00:00
|
|
|
ErrorMessage string
|
2023-10-19 10:19:10 +00:00
|
|
|
// IsGlobal defines if the unique constraint is globally unique or just within a single instance
|
2022-05-16 09:52:54 +00:00
|
|
|
IsGlobal bool
|
2021-01-21 09:49:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
type UniqueConstraintAction int8
|
2021-01-21 09:49:38 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
UniqueConstraintAdd UniqueConstraintAction = iota
|
|
|
|
UniqueConstraintRemove
|
2022-10-26 13:06:48 +00:00
|
|
|
UniqueConstraintInstanceRemove
|
2023-10-19 10:19:10 +00:00
|
|
|
|
|
|
|
uniqueConstraintActionCount
|
2021-01-21 09:49:38 +00:00
|
|
|
)
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func (f UniqueConstraintAction) Valid() bool {
|
|
|
|
return f >= 0 && f < uniqueConstraintActionCount
|
|
|
|
}
|
|
|
|
|
2021-01-21 09:49:38 +00:00
|
|
|
func NewAddEventUniqueConstraint(
|
|
|
|
uniqueType,
|
|
|
|
uniqueField,
|
2023-10-19 10:19:10 +00:00
|
|
|
errMessage string) *UniqueConstraint {
|
|
|
|
return &UniqueConstraint{
|
2021-01-21 09:49:38 +00:00
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
ErrorMessage: errMessage,
|
|
|
|
Action: UniqueConstraintAdd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func NewRemoveUniqueConstraint(
|
2021-01-21 09:49:38 +00:00
|
|
|
uniqueType,
|
2023-10-19 10:19:10 +00:00
|
|
|
uniqueField string) *UniqueConstraint {
|
|
|
|
return &UniqueConstraint{
|
2021-01-21 09:49:38 +00:00
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
Action: UniqueConstraintRemove,
|
|
|
|
}
|
|
|
|
}
|
2022-05-16 09:52:54 +00:00
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func NewRemoveInstanceUniqueConstraints() *UniqueConstraint {
|
|
|
|
return &UniqueConstraint{
|
2022-10-26 13:06:48 +00:00
|
|
|
Action: UniqueConstraintInstanceRemove,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func NewAddGlobalUniqueConstraint(
|
2022-05-16 09:52:54 +00:00
|
|
|
uniqueType,
|
|
|
|
uniqueField,
|
2023-10-19 10:19:10 +00:00
|
|
|
errMessage string) *UniqueConstraint {
|
|
|
|
return &UniqueConstraint{
|
2022-05-16 09:52:54 +00:00
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
ErrorMessage: errMessage,
|
|
|
|
IsGlobal: true,
|
|
|
|
Action: UniqueConstraintAdd,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 10:19:10 +00:00
|
|
|
func NewRemoveGlobalUniqueConstraint(
|
2022-05-16 09:52:54 +00:00
|
|
|
uniqueType,
|
2023-10-19 10:19:10 +00:00
|
|
|
uniqueField string) *UniqueConstraint {
|
|
|
|
return &UniqueConstraint{
|
2022-05-16 09:52:54 +00:00
|
|
|
UniqueType: uniqueType,
|
|
|
|
UniqueField: uniqueField,
|
|
|
|
IsGlobal: true,
|
|
|
|
Action: UniqueConstraintRemove,
|
|
|
|
}
|
|
|
|
}
|