From a1fded7ac592cee5100a54a8842dc74d20c30a96 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Mon, 11 Nov 2024 10:16:00 +0500 Subject: [PATCH 1/2] Add new table and schema for wf_requests --- db/config.go | 1 + db/structs.go | 14 ++++++++++++++ db/test_config.go | 1 + 3 files changed, 16 insertions(+) diff --git a/db/config.go b/db/config.go index 4abd9f4cb..4be9de041 100644 --- a/db/config.go +++ b/db/config.go @@ -81,6 +81,7 @@ func InitDB() { db.AutoMigrate(&WorkspaceFeatures{}) db.AutoMigrate(&FeaturePhase{}) db.AutoMigrate(&FeatureStory{}) + db.AutoMigrate(&WfRequest{}) DB.MigrateTablesWithOrgUuid() DB.MigrateOrganizationToWorkspace() diff --git a/db/structs.go b/db/structs.go index 9a125ced6..f9916c692 100644 --- a/db/structs.go +++ b/db/structs.go @@ -910,6 +910,16 @@ type FilterStattuCount struct { Failed int64 `json:"failed"` } +type WfRequest struct { + ID uint `gorm:"primaryKey;autoIncrement" json:"id"` + RequestID string `gorm:"unique;not null" json:"request_id"` + Status string `json:"status"` + RequestData JSONB `json:"request_data"` + ResponseData JSONB `gorm:"type:jsonb" json:"response_data,omitempty"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + func (Person) TableName() string { return "people" } @@ -946,6 +956,10 @@ func (ConnectionCodesShort) TableName() string { return "connectioncodes" } +func (WfRequest) TableName() string { + return "wf_requests" +} + // PropertyMap ... type PropertyMap map[string]interface{} diff --git a/db/test_config.go b/db/test_config.go index 4416b8b55..60198f802 100644 --- a/db/test_config.go +++ b/db/test_config.go @@ -58,6 +58,7 @@ func InitTestDB() { db.AutoMigrate(&WorkspaceUsers{}) db.AutoMigrate(&WorkspaceUserRoles{}) db.AutoMigrate(&Bot{}) + db.AutoMigrate(&WfRequest{}) people := TestDB.GetAllPeople() for _, p := range people { From ea10cf9583e4f316939b8f7548ec37d48b82fea9 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Mon, 11 Nov 2024 16:59:03 +0500 Subject: [PATCH 2/2] Add enum for WfRequest status; use JSONB for data fields --- db/structs.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/db/structs.go b/db/structs.go index f9916c692..443ac971e 100644 --- a/db/structs.go +++ b/db/structs.go @@ -910,14 +910,23 @@ type FilterStattuCount struct { Failed int64 `json:"failed"` } +type WfRequestStatus string + +const ( + StatusNew WfRequestStatus = "NEW" + StatusPending WfRequestStatus = "PENDING" + StatusCompleted WfRequestStatus = "COMPLETED" + StatusFailed WfRequestStatus = "FAILED" +) + type WfRequest struct { - ID uint `gorm:"primaryKey;autoIncrement" json:"id"` - RequestID string `gorm:"unique;not null" json:"request_id"` - Status string `json:"status"` - RequestData JSONB `json:"request_data"` - ResponseData JSONB `gorm:"type:jsonb" json:"response_data,omitempty"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + ID uint `gorm:"primaryKey;autoIncrement" json:"id"` + RequestID string `gorm:"unique;not null" json:"request_id"` + Status WfRequestStatus `json:"status"` + RequestData JSONB `gorm:"type:jsonb" json:"request_data"` + ResponseData JSONB `gorm:"type:jsonb" json:"response_data,omitempty"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } func (Person) TableName() string {