-
Notifications
You must be signed in to change notification settings - Fork 1
/
artifacts.go
43 lines (37 loc) · 1.67 KB
/
artifacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package models
import (
"time"
"github.com/google/uuid"
"github.com/samber/lo"
"gorm.io/gorm"
)
// Artifact represents the artifacts table
type Artifact struct {
ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"`
CheckID *uuid.UUID `json:"check_id,omitempty"`
CheckTime *time.Time `json:"check_time,omitempty" time_format:"postgres_timestamp"`
PlaybookRunActionID *uuid.UUID `json:"playbook_run_action_id,omitempty"`
ConnectionID uuid.UUID `json:"connection_id,omitempty"`
Path string `json:"path"`
IsPushed bool `json:"is_pushed"`
IsDataPushed bool `json:"is_data_pushed"`
Filename string `json:"filename"`
Size int64 `json:"size"` // Size in bytes
ContentType string `json:"content_type,omitempty"`
Checksum string `json:"checksum"`
CreatedAt time.Time `json:"created_at" yaml:"created_at" time_format:"postgres_timestamp"`
UpdatedAt time.Time `json:"updated_at" yaml:"updated_at" time_format:"postgres_timestamp"`
DeletedAt *time.Time `json:"deleted_at,omitempty" yaml:"deleted_at,omitempty" time_format:"postgres_timestamp"`
ExpiresAt *time.Time `json:"expires_at,omitempty" yaml:"expires_at,omitempty" time_format:"postgres_timestamp"`
}
func (t Artifact) TableName() string {
return "artifacts"
}
func (t Artifact) PK() string {
return t.ID.String()
}
func (t Artifact) GetUnpushed(db *gorm.DB) ([]DBTable, error) {
var items []Artifact
err := db.Where("is_pushed IS FALSE").Find(&items).Error
return lo.Map(items, func(i Artifact, _ int) DBTable { return i }), err
}