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