deployment.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package models
  2. import (
  3. "time"
  4. "gorm.io/gorm"
  5. )
  6. // Deployment represents a deployed instance of an application
  7. type Deployment struct {
  8. ID int64 `gorm:"column:rowid;primaryKey;autoIncrement" json:"id"` // Unique identifier
  9. Name string `json:"name" gorm:"not null"` // Deployment name
  10. Description string `json:"description"` // Deployment description
  11. // Core relationships
  12. AppID int64 `json:"appId" gorm:"index"` // Reference to the app being deployed (was TemplateID)
  13. ClientID int64 `json:"clientId" gorm:"index"` // Client this deployment belongs to
  14. // Status and environment
  15. Status string `json:"status" gorm:"default:'pending'"` // Current deployment status
  16. Environment string `json:"environment" gorm:"default:'development'"` // dev, staging, production
  17. Region string `json:"region"` // Geographic region
  18. // Deployment configuration
  19. Hostname string `json:"hostname"` // External hostname for the deployment
  20. CustomDomain string `json:"customDomain"` // Custom domain if configured
  21. // Operational data
  22. LogsConfig string `json:"logsConfig" gorm:"type:text"` // Logging configuration as JSON
  23. MetricsConfig string `json:"metricsConfig" gorm:"type:text"` // Metrics configuration as JSON
  24. AlertsConfig string `json:"alertsConfig" gorm:"type:text"` // Alert configurations as JSON
  25. CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"` // Creation timestamp
  26. UpdatedAt time.Time `json:"updatedAt" gorm:"autoUpdateTime"` // Last update timestamp
  27. LastDeployedAt time.Time `json:"lastDeployedAt"` // When the deployment was last deployed
  28. CreatedBy string `json:"createdBy" gorm:"index"` // User ID who created the deployment
  29. DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` // Soft delete support
  30. // GORM relationships
  31. DeployedComponents []DeployedComponent `json:"deployedComponents" gorm:"foreignKey:DeploymentID"` // Array of deployed components
  32. }
  33. // DeployedApp represents a specific app within a deployment
  34. type DeployedApp struct {
  35. ID int64 `gorm:"column:rowid;primaryKey;autoIncrement" json:"id"` // Unique identifier
  36. DeploymentID int64 `json:"deploymentId" gorm:"index"` // Reference to the parent deployment
  37. ComponentID int64 `json:"componentId" gorm:"index"` // Reference to the component being deployed (was AppID)
  38. Status string `json:"status" gorm:"default:'pending'"` // Status of this specific app's deployment
  39. Version string `json:"version"` // Deployed version
  40. URL string `json:"url"` // URL to access this app
  41. PodCount int `json:"podCount" gorm:"default:1"` // Number of running instances/pods
  42. HealthStatus string `json:"healthStatus" gorm:"default:'pending'"` // Current health status
  43. ConfigSnapshot string `json:"configSnapshot" gorm:"type:text"` // Snapshot of configuration at deployment time
  44. CreatedAt time.Time `json:"createdAt" gorm:"autoCreateTime"` // Creation timestamp
  45. UpdatedAt time.Time `json:"updatedAt" gorm:"autoUpdateTime"` // Last update timestamp
  46. DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` // Soft delete support
  47. // GORM relationships - these will be serialized/deserialized as JSON
  48. Resources ResourceAllocation `json:"resources" gorm:"-"` // Actual resources allocated
  49. }
  50. // App resource allocation (will be stored in DeployedAppResource table)
  51. type DeployedAppResource struct {
  52. ID int64 `gorm:"column:rowid;primaryKey;autoIncrement" json:"id"` // Unique identifier
  53. DeployedAppID int64 `json:"deployedAppId" gorm:"uniqueIndex"` // Reference to deployed app
  54. CPU string `json:"cpu"` // Allocated CPU
  55. CPUUsage float64 `json:"cpuUsage"` // Current CPU usage percentage
  56. Memory string `json:"memory"` // Allocated memory
  57. MemoryUsage float64 `json:"memoryUsage"` // Current memory usage percentage
  58. Storage string `json:"storage"` // Allocated storage
  59. StorageUsage float64 `json:"storageUsage"` // Current storage usage percentage
  60. LastUpdated time.Time `json:"lastUpdated" gorm:"autoUpdateTime"` // When metrics were last updated
  61. }
  62. // For backward compatibility
  63. type ResourceAllocation struct {
  64. CPU string `json:"cpu"` // Allocated CPU
  65. CPUUsage float64 `json:"cpuUsage"` // Current CPU usage percentage
  66. Memory string `json:"memory"` // Allocated memory
  67. MemoryUsage float64 `json:"memoryUsage"` // Current memory usage percentage
  68. Storage string `json:"storage"` // Allocated storage
  69. StorageUsage float64 `json:"storageUsage"` // Current storage usage percentage
  70. }
  71. // LogConfiguration, MetricsConfiguration, and AlertConfiguration remain the same
  72. // These will be serialized/deserialized as JSON
  73. type LogConfiguration struct {
  74. Enabled bool `json:"enabled"` // Whether logging is enabled
  75. RetentionDays int `json:"retentionDays"` // Number of days to retain logs
  76. ExternalSink string `json:"externalSink"` // External logging system URL if any
  77. }
  78. type MetricsConfiguration struct {
  79. Enabled bool `json:"enabled"` // Whether metrics collection is enabled
  80. RetentionDays int `json:"retentionDays"` // Number of days to retain metrics
  81. CustomMetrics []string `json:"customMetrics"` // Any custom metrics to collect
  82. }
  83. type AlertConfiguration struct {
  84. Type string `json:"type"` // Type of alert
  85. Threshold float64 `json:"threshold"` // Threshold value
  86. Operator string `json:"operator"` // ">", "<", ">=", "<=", "=="
  87. Duration string `json:"duration"` // How long condition must be true before alerting
  88. NotificationChannels []string `json:"notificationChannels"` // Channels to notify (email, slack, etc.)
  89. }
  90. // DeploymentStatus type definitions
  91. type DeploymentStatus string
  92. type Environment string
  93. type ComponentDeploymentStatus string
  94. type HealthStatus string
  95. type AlertType string
  96. const (
  97. // DeploymentStatus values
  98. PENDING_DEPLOYMENT DeploymentStatus = "pending"
  99. DEPLOYING DeploymentStatus = "deploying"
  100. DEPLOYED DeploymentStatus = "deployed"
  101. FAILED_DEPLOYMENT DeploymentStatus = "failed"
  102. UPDATING_DEPLOYMENT DeploymentStatus = "updating"
  103. DELETING DeploymentStatus = "deleting"
  104. // Environment values
  105. DEVELOPMENT Environment = "development"
  106. STAGING Environment = "staging"
  107. PRODUCTION Environment = "production"
  108. // ComponentDeploymentStatus values
  109. PENDING_APP ComponentDeploymentStatus = "pending"
  110. RUNNING ComponentDeploymentStatus = "running"
  111. FAILED_APP ComponentDeploymentStatus = "failed"
  112. SCALING ComponentDeploymentStatus = "scaling"
  113. UPDATING_APP ComponentDeploymentStatus = "updating"
  114. // HealthStatus values
  115. HEALTHY HealthStatus = "healthy"
  116. DEGRADED HealthStatus = "degraded"
  117. UNHEALTHY HealthStatus = "unhealthy"
  118. // AlertType values
  119. CPU_USAGE AlertType = "cpu_usage"
  120. MEMORY_USAGE AlertType = "memory_usage"
  121. DISK_USAGE AlertType = "disk_usage"
  122. ERROR_RATE AlertType = "error_rate"
  123. LATENCY AlertType = "latency"
  124. )