This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
project.go
143 lines (135 loc) · 4.17 KB
/
project.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/index"
"github.com/seal-io/walrus/pkg/dao/entx"
"github.com/seal-io/walrus/pkg/dao/schema/intercept"
"github.com/seal-io/walrus/pkg/dao/schema/mixin"
)
type Project struct {
ent.Schema
}
func (Project) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.Metadata(),
}
}
func (Project) Indexes() []ent.Index {
return []ent.Index{
index.Fields("name").
Unique(),
}
}
func (Project) Edges() []ent.Edge {
return []ent.Edge{
// Project 1-* Environments.
edge.To("environments", Environment.Type).
Comment("Environments that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Restrict),
entx.SkipIO()),
// Project 1-* Connectors.
edge.To("connectors", Connector.Type).
Comment("Connectors that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* Roles (Subject).
edge.To("subject_roles", SubjectRoleRelationship.Type).
Comment("Roles of a subject that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipOutput()),
// Project 1-* Resources.
edge.To("resources", Resource.Type).
Comment("Resources that belong to the project.").
Annotations(
entsql.OnDelete(entsql.NoAction),
entx.SkipIO()),
// Project 1-* ResourceComponents.
edge.To("resource_components", ResourceComponent.Type).
Comment("ResourceComponents that belong to the project.").
Annotations(
entsql.OnDelete(entsql.NoAction),
entx.SkipIO()),
// Project 1-* ResourceRevisions.
edge.To("resource_revisions", ResourceRevision.Type).
Comment("ResourceRevisions that belong to the project.").
Annotations(
entsql.OnDelete(entsql.NoAction),
entx.SkipIO()),
// Project 1-* Variables.
edge.To("variables", Variable.Type).
Comment("Variables that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* Templates.
edge.To("templates", Template.Type).
Comment("Templates that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* TemplateVersions.
edge.To("template_versions", TemplateVersion.Type).
Comment("TemplateVersions that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* Catalogs.
edge.To("catalogs", Catalog.Type).
Comment("Catalogs that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* Workflows.
edge.To("workflows", Workflow.Type).
Comment("Workflows that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* WorkflowStages.
edge.To("workflow_stages", WorkflowStage.Type).
Comment("WorkflowStages that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* WorkflowSteps.
edge.To("workflow_steps", WorkflowStep.Type).
Comment("WorkflowSteps that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* WorkflowExecutions.
edge.To("workflow_executions", WorkflowExecution.Type).
Comment("WorkflowExecutions that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* WorkflowStageExecutions.
edge.To("workflow_stage_executions", WorkflowStageExecution.Type).
Comment("WorkflowStageExecutions that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
// Project 1-* WorkflowStepExecutions.
edge.To("workflow_step_executions", WorkflowStepExecution.Type).
Comment("WorkflowStepExecutions that belong to the project.").
Annotations(
entsql.OnDelete(entsql.Cascade),
entx.SkipIO()),
}
}
func (Project) Annotations() []schema.Annotation {
return []schema.Annotation{
entx.ValidateContext(intercept.WithProjectInterceptor),
}
}
func (Project) Interceptors() []ent.Interceptor {
return []ent.Interceptor{
intercept.ByProject("id"),
}
}