mirror of
https://github.com/coder/coder.git
synced 2026-10-28 02:42:54 +08:00
feat: add API support for workspace automatic updates (#10099)
* Added automatic_updates to workspaces table Signed-off-by: Spike Curtis <spike@coder.com> * Queries and API updates Signed-off-by: Spike Curtis <spike@coder.com> * Golden files Signed-off-by: Spike Curtis <spike@coder.com> * Enable automatic updates on autostart Signed-off-by: Spike Curtis <spike@coder.com> * db migration number Signed-off-by: Spike Curtis <spike@coder.com> * fix imports and ts mock Signed-off-by: Spike Curtis <spike@coder.com> * code review updates Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
This commit is contained in:
+72
-13
@@ -211,6 +211,64 @@ func AllAuditActionValues() []AuditAction {
|
||||
}
|
||||
}
|
||||
|
||||
type AutomaticUpdates string
|
||||
|
||||
const (
|
||||
AutomaticUpdatesAlways AutomaticUpdates = "always"
|
||||
AutomaticUpdatesNever AutomaticUpdates = "never"
|
||||
)
|
||||
|
||||
func (e *AutomaticUpdates) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = AutomaticUpdates(s)
|
||||
case string:
|
||||
*e = AutomaticUpdates(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for AutomaticUpdates: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullAutomaticUpdates struct {
|
||||
AutomaticUpdates AutomaticUpdates `json:"automatic_updates"`
|
||||
Valid bool `json:"valid"` // Valid is true if AutomaticUpdates is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullAutomaticUpdates) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.AutomaticUpdates, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.AutomaticUpdates.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullAutomaticUpdates) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.AutomaticUpdates), nil
|
||||
}
|
||||
|
||||
func (e AutomaticUpdates) Valid() bool {
|
||||
switch e {
|
||||
case AutomaticUpdatesAlways,
|
||||
AutomaticUpdatesNever:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func AllAutomaticUpdatesValues() []AutomaticUpdates {
|
||||
return []AutomaticUpdates{
|
||||
AutomaticUpdatesAlways,
|
||||
AutomaticUpdatesNever,
|
||||
}
|
||||
}
|
||||
|
||||
type BuildReason string
|
||||
|
||||
const (
|
||||
@@ -1995,19 +2053,20 @@ type VisibleUser struct {
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
OwnerID uuid.UUID `db:"owner_id" json:"owner_id"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
TemplateID uuid.UUID `db:"template_id" json:"template_id"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Name string `db:"name" json:"name"`
|
||||
AutostartSchedule sql.NullString `db:"autostart_schedule" json:"autostart_schedule"`
|
||||
Ttl sql.NullInt64 `db:"ttl" json:"ttl"`
|
||||
LastUsedAt time.Time `db:"last_used_at" json:"last_used_at"`
|
||||
DormantAt sql.NullTime `db:"dormant_at" json:"dormant_at"`
|
||||
DeletingAt sql.NullTime `db:"deleting_at" json:"deleting_at"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
OwnerID uuid.UUID `db:"owner_id" json:"owner_id"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
|
||||
TemplateID uuid.UUID `db:"template_id" json:"template_id"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Name string `db:"name" json:"name"`
|
||||
AutostartSchedule sql.NullString `db:"autostart_schedule" json:"autostart_schedule"`
|
||||
Ttl sql.NullInt64 `db:"ttl" json:"ttl"`
|
||||
LastUsedAt time.Time `db:"last_used_at" json:"last_used_at"`
|
||||
DormantAt sql.NullTime `db:"dormant_at" json:"dormant_at"`
|
||||
DeletingAt sql.NullTime `db:"deleting_at" json:"deleting_at"`
|
||||
AutomaticUpdates AutomaticUpdates `db:"automatic_updates" json:"automatic_updates"`
|
||||
}
|
||||
|
||||
type WorkspaceAgent struct {
|
||||
|
||||
Reference in New Issue
Block a user