INFRA-2830 | adding version column in incident entity (#403)
This commit is contained in:
1
go.mod
1
go.mod
@@ -26,6 +26,7 @@ require (
|
||||
gorm.io/datatypes v1.2.0
|
||||
gorm.io/driver/postgres v1.5.7
|
||||
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde
|
||||
gorm.io/plugin/optimisticlock v1.1.1
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
9
model/base_entity.go
Normal file
9
model/base_entity.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
import "gorm.io/gorm"
|
||||
import "gorm.io/plugin/optimisticlock"
|
||||
|
||||
type BaseEntity struct {
|
||||
gorm.Model
|
||||
Version optimisticlock.Version `gorm:"column:version;default:0"`
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package incident
|
||||
|
||||
import (
|
||||
"houston/model"
|
||||
"houston/model/product"
|
||||
"time"
|
||||
|
||||
@@ -44,7 +45,7 @@ const (
|
||||
|
||||
// IncidentEntity all the incident created will go in this table
|
||||
type IncidentEntity struct {
|
||||
gorm.Model
|
||||
model.BaseEntity
|
||||
Title string `gorm:"column:title"`
|
||||
Description string `gorm:"column:description"`
|
||||
Status uint `gorm:"column:status"`
|
||||
|
||||
@@ -224,7 +224,7 @@ func (r *Repository) captureLogs(justification string) {
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateIncident(incidentEntity *IncidentEntity) error {
|
||||
result := r.gormClient.Updates(incidentEntity)
|
||||
result := r.gormClient.Select("*").Updates(incidentEntity)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func (r *Repository) UpdateIncidentWithAssociations(incidentEntity *IncidentEnti
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result := r.gormClient.Updates(incidentEntity)
|
||||
result := r.gormClient.Select("*").Updates(incidentEntity)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func (r *Repository) UpdateIncidentWithAssociations(incidentEntity *IncidentEnti
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateIncidentWithJustification(incidentEntity *IncidentEntity, justification string) error {
|
||||
result := r.gormClient.Updates(incidentEntity)
|
||||
result := r.gormClient.Select("*").Updates(incidentEntity)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"houston/logger"
|
||||
"houston/mocks"
|
||||
"houston/model"
|
||||
"houston/model/incident"
|
||||
"houston/model/incident_channel"
|
||||
"houston/model/severity"
|
||||
@@ -321,7 +322,7 @@ func (suite *IncidentServiceSuite) Test_UpdateIncident_SlackError() {
|
||||
|
||||
func GetMockIncident() *incident.IncidentEntity {
|
||||
return &incident.IncidentEntity{
|
||||
Model: gorm.Model{ID: 1},
|
||||
BaseEntity: model.BaseEntity{Model: gorm.Model{ID: 1}},
|
||||
Title: "Mock Title",
|
||||
Description: "Mock Description",
|
||||
Status: 1,
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"houston/common/util"
|
||||
"houston/logger"
|
||||
"houston/mocks"
|
||||
@@ -670,7 +669,7 @@ func getMockUsers() *[]user.UserEntity {
|
||||
|
||||
func GetMockIncident() *incident.IncidentEntity {
|
||||
return &incident.IncidentEntity{
|
||||
Model: gorm.Model{},
|
||||
BaseEntity: model.BaseEntity{},
|
||||
Title: "Mock Title",
|
||||
Description: "Mock Description",
|
||||
Status: 1,
|
||||
|
||||
Reference in New Issue
Block a user