porter_app_event.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package models
  2. import (
  3. "time"
  4. "github.com/google/uuid"
  5. "github.com/porter-dev/porter/api/types"
  6. "gorm.io/gorm"
  7. )
  8. // PorterAppEvent represents an event that occurs on a Porter stack during a stacks lifecycle.
  9. type PorterAppEvent struct {
  10. gorm.Model
  11. // ID is a unique identifier for a given event
  12. ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
  13. // Status contains the accepted status' of a given event such as SUCCESS, FAILED, PROGRESSING, etc.
  14. Status string `json:"status"`
  15. // Type represents a supported Porter Stack Event
  16. Type string `json:"type"`
  17. // TypeExternalSource represents an external event source such as Github, or Gitlab. This is not always required but will commonly be see in build events
  18. TypeExternalSource string `json:"type_source,omitempty"`
  19. // CreatedAt is the time (UTC) that a given event was created. This should not change
  20. CreatedAt time.Time `json:"created_at"`
  21. // UpdatedAt is the time (UTC) that an event was last updated. This can occur when an event was created as PROGRESSING, then was marked as SUCCESSFUL for example
  22. UpdatedAt time.Time `json:"updated_at"`
  23. // PorterAppID is the ID that the given event relates to
  24. PorterAppID uint `json:"porter_app_id" gorm:"index:idx_app_deployment_target"`
  25. // DeploymentTargetID is the ID of the deployment target that the event relates to
  26. DeploymentTargetID uuid.UUID `json:"deployment_target_id" gorm:"type:uuid;index:idx_app_deployment_target;default:00000000-0000-0000-0000-000000000000"`
  27. Metadata JSONB `json:"metadata" sql:"type:jsonb" gorm:"type:jsonb"`
  28. }
  29. // TableName overrides the table name
  30. func (PorterAppEvent) TableName() string {
  31. return "porter_app_events"
  32. }
  33. func (p *PorterAppEvent) ToPorterAppEvent() types.PorterAppEvent {
  34. if p == nil {
  35. return types.PorterAppEvent{}
  36. }
  37. ty := types.PorterAppEvent{
  38. ID: p.ID.String(),
  39. Status: p.Status,
  40. Type: types.PorterAppEventType(p.Type),
  41. TypeExternalSource: p.TypeExternalSource,
  42. CreatedAt: p.CreatedAt,
  43. UpdatedAt: p.UpdatedAt,
  44. PorterAppID: p.PorterAppID,
  45. DeploymentTargetID: p.DeploymentTargetID.String(),
  46. }
  47. if p.Metadata != nil {
  48. ty.Metadata = p.Metadata
  49. }
  50. return ty
  51. }