From 9debc6af9ff24558da0ce313b3741432bf9ba749 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Mon, 9 Dec 2024 18:04:09 +0500 Subject: [PATCH] feat(tickets): add optional fields for grouping and authorship --- db/migrations_test.go | 35 ++++++++++++++++++++++++++++++++++- db/structs.go | 11 ++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/db/migrations_test.go b/db/migrations_test.go index 3d21e130c..a588906a8 100644 --- a/db/migrations_test.go +++ b/db/migrations_test.go @@ -19,18 +19,48 @@ func TestTicketsMigrationPostgres(t *testing.T) { } // Check if columns exist - columns := []string{"uuid", "feature_uuid", "phase_uuid", "name", "sequence", "dependency", "description", "status", "created_at", "updated_at"} + columns := []string{ + "uuid", + "ticket_group", + "feature_uuid", + "phase_uuid", + "name", + "sequence", + "dependency", + "description", + "status", + "version", + "author", + "author_id", + "created_at", + "updated_at", + } + for _, column := range columns { if !TestDB.db.Migrator().HasColumn(&Tickets{}, column) { t.Errorf("Column %s is missing in the 'tickets' table", column) } } + indexes := []string{ + "group_index", + "composite_index", + "phase_index", + } + + for _, index := range indexes { + hasIndex := TestDB.db.Migrator().HasIndex(&Tickets{}, index) + if !hasIndex { + t.Errorf("Index %s is missing in the 'tickets' table", index) + } + } + t.Log("Migration test for Tickets struct with PostgreSQL passed") } type TestTickets struct { UUID uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"` + TicketGroup *uuid.UUID `gorm:"type:uuid;index:group_index" json:"ticket_group,omitempty"` FeatureUUID string `gorm:"type:uuid;not null" json:"feature_uuid" validate:"required"` PhaseUUID string `gorm:"type:uuid;not null" json:"phase_uuid" validate:"required"` Name string `gorm:"type:varchar(255);not null"` @@ -38,6 +68,9 @@ type TestTickets struct { Dependency []int `gorm:"type:integer[]"` Description string `gorm:"type:text"` Status TicketStatus `gorm:"type:varchar(50);not null;default:'draft'"` + Version *int `gorm:"type:integer" json:"version,omitempty"` + Author *Author `gorm:"type:varchar(50)" json:"author,omitempty"` + AuthorID *string `gorm:"type:varchar(255)" json:"author_id,omitempty"` CreatedAt time.Time `gorm:"type:timestamp;not null;default:current_timestamp" json:"created_at"` UpdatedAt time.Time `gorm:"type:timestamp;not null;default:current_timestamp" json:"updated_at"` } diff --git a/db/structs.go b/db/structs.go index 1cd3ed322..a5e8d03bc 100644 --- a/db/structs.go +++ b/db/structs.go @@ -947,6 +947,8 @@ type WfRequest struct { type TicketStatus string +type Author string + const ( DraftTicket TicketStatus = "DRAFT" ReadyTicket TicketStatus = "READY" @@ -957,8 +959,14 @@ const ( CompletedTicket TicketStatus = "COMPLETED" ) +const ( + HumanAuthor Author = "HUMAN" + AgentAuthor Author = "AGENT" +) + type Tickets struct { UUID uuid.UUID `gorm:"primaryKey;type:uuid"` + TicketGroup *uuid.UUID `gorm:"type:uuid;index:group_index" json:"ticket_group,omitempty"` FeatureUUID string `gorm:"type:varchar(255);index:composite_index" json:"feature_uuid"` Features WorkspaceFeatures `gorm:"foreignKey:FeatureUUID;references:Uuid"` PhaseUUID string `gorm:"type:varchar(255);index:phase_index" json:"phase_uuid"` @@ -969,10 +977,11 @@ type Tickets struct { Description string `gorm:"type:text" json:"description"` Status TicketStatus `gorm:"type:varchar(50);default:'DRAFT'" json:"status"` Version int `gorm:"type:integer;default:0" json:"version"` + Author *Author `gorm:"type:varchar(50)" json:"author,omitempty"` + AuthorID *string `gorm:"type:varchar(255)" json:"author_id,omitempty"` CreatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` UpdatedAt time.Time `gorm:"type:timestamp;default:current_timestamp" json:"updated_at"` } - type BroadcastType string const (