Skip to content

Commit

Permalink
Merge pull request #2138 from aliraza556/feature-tickets-optional-fields
Browse files Browse the repository at this point in the history
[FEAT] Update Database Migration and Tickets Struct for Optional Fields
  • Loading branch information
humansinstitute authored Dec 10, 2024
2 parents a6901e5 + 9debc6a commit e68cbf3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
35 changes: 34 additions & 1 deletion db/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,58 @@ 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"`
Sequence int `gorm:"type:integer;not null;index:composite_index"`
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"`
}
Expand Down
11 changes: 10 additions & 1 deletion db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ type WfRequest struct {

type TicketStatus string

type Author string

const (
DraftTicket TicketStatus = "DRAFT"
ReadyTicket TicketStatus = "READY"
Expand All @@ -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"`
Expand All @@ -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 (
Expand Down

0 comments on commit e68cbf3

Please sign in to comment.