datastore.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "github.com/google/uuid"
  4. "gorm.io/gorm"
  5. )
  6. // DatastoreStatus is the status of an app revision
  7. type DatastoreStatus string
  8. const (
  9. // DatastoreStatus_Creating is the status for a datastore that is being created
  10. DatastoreStatus_Creating DatastoreStatus = "CREATING"
  11. // DatastoreStatus_Available is the status for a datastore that is available
  12. DatastoreStatus_Available DatastoreStatus = "AVAILABLE"
  13. // DatastoreStatus_AwaitingDeletion is the status for a datastore that is awaiting deletion
  14. DatastoreStatus_AwaitingDeletion DatastoreStatus = "AWAITING_DELETION"
  15. )
  16. // Datastore is a database model that represents a Porter-provisioned datastore
  17. type Datastore struct {
  18. gorm.Model
  19. // ID is a uuid that references the datastore
  20. ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
  21. // ProjectID is the ID of the project that the datastore belongs to
  22. ProjectID uint `json:"project_id"`
  23. // Name is the name of the datastore
  24. Name string `json:"name"`
  25. // CloudProvider is the cloud provider that hosts the Kubernetes Cluster. Accepted values: [AWS, GCP, AZURE]
  26. CloudProvider string `json:"cloud_provider"`
  27. // CloudProviderCredentialIdentifier is a reference to find the credentials required for access the cluster's API.
  28. // This was likely the credential that was used to create the cluster.
  29. // For AWS EKS clusters, this will be an ARN for the final target role in the assume role chain.
  30. CloudProviderCredentialIdentifier string `json:"cloud_provider_credential_identifier"`
  31. // Type is the type of datastore. Accepted values: [RDS, ELASTICACHE, MANAGED_POSTGRES, MANAGED_REDIS]
  32. Type string `json:"type"`
  33. // Engine is the engine of the datastore. Accepted values: [POSTGRES, AURORA-POSTGRES, REDIS]
  34. Engine string `json:"engine"`
  35. // Status describes the status of a datastore
  36. Status DatastoreStatus `json:"status"`
  37. // OnManagementCluster is a flag that indicates whether the datastore is hosted on the management cluster or on the customer's cluster
  38. OnManagementCluster bool `json:"on_management_cluster" gorm:"not null;default:false"`
  39. }
  40. // IsLegacy returns true if the datastore is a legacy datastore
  41. func (d *Datastore) IsLegacy() bool {
  42. return !d.OnManagementCluster && !(d.Type == "MANAGED_POSTGRES" || d.Type == "MANAGED_REDIS")
  43. }