This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathdeployment.go
More file actions
115 lines (109 loc) · 2.5 KB
/
deployment.go
File metadata and controls
115 lines (109 loc) · 2.5 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Deployment holds the schema definition for the Deployment entity.
type Deployment struct {
ent.Schema
}
// Fields of the Deployment.
func (Deployment) Fields() []ent.Field {
return []ent.Field{
field.Int("number"),
field.Enum("type").
Values(
"commit",
"branch",
"tag",
).
Default("commit"),
field.String("env"),
field.String("ref"),
field.Enum("status").
Values(
"waiting",
"created",
"queued",
"running",
"success",
"failure",
"canceled",
).
Default("waiting"),
// UID, SHA, and HTLM URL are returned after
// the remote deployment is created.
field.Int64("uid").
Optional(),
field.String("sha").
Optional(),
field.String("html_url").
MaxLen(2000).
Optional(),
field.Bool("production_environment").
Default(false),
field.Bool("is_rollback").
Default(false),
field.Time("created_at").
Default(nowUTC),
field.Time("updated_at").
Default(nowUTC).
UpdateDefault(nowUTC),
// Edges
field.Int64("user_id"),
field.Int64("repo_id"),
// Deprecated fields.
field.Bool("is_approval_enabled").
Optional().
Nillable(),
field.Int("required_approval_count").
Optional().
Nillable(),
}
}
// Edges of the Deployment.
func (Deployment) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("deployments").
Field("user_id").
Unique().
Required(),
edge.From("repo", Repo.Type).
Ref("deployments").
Field("repo_id").
Unique().
Required(),
edge.To("reviews", Review.Type).
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
edge.To("deployment_statuses", DeploymentStatus.Type).
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
edge.To("event", Event.Type).
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
}
}
func (Deployment) Indexes() []ent.Index {
return []ent.Index{
// Find the latest succeed deployment.
index.Fields("repo_id", "env", "status", "updated_at"),
// List deployments by the env.
index.Fields("repo_id", "env", "created_at"),
index.Fields("repo_id", "created_at"),
// The deployment number is unique for the repo.
index.Fields("number", "repo_id").
Unique(),
// Find by UID when the hook is coming.
index.Fields("uid"),
// List inactive deployments for 30 minutes.
index.Fields("status", "created_at"),
}
}