Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Update Database Migration and Tickets Struct for Optional Fields #2138

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading