INFRA-2830 | adding version column in incident entity (#403)

This commit is contained in:
Shashank Shekhar
2024-03-20 16:26:56 +05:30
committed by GitHub
parent 38d5095fd9
commit 3945abcb8f
6 changed files with 18 additions and 7 deletions

1
go.mod
View File

@@ -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
View 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"`
}

View File

@@ -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"`

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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,