Skip to content

Commit d3aaeb6

Browse files
authored
Merge pull request #80 from buildbarn/feature/db-cleanup
Add graphql mutations to delete builds and invocations
2 parents db914e1 + b12b339 commit d3aaeb6

37 files changed

+1979
-925
lines changed

ent/gen/ent/migrate/schema.go

+65-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/schema/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ go_library(
5151
"@com_github_google_uuid//:uuid",
5252
"@io_entgo_contrib//entgql",
5353
"@io_entgo_ent//:ent",
54+
"@io_entgo_ent//dialect/entsql",
5455
"@io_entgo_ent//schema",
5556
"@io_entgo_ent//schema/edge",
5657
"@io_entgo_ent//schema/field",

ent/schema/actioncachestatistics.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
"entgo.io/ent/schema/field"
78
)
@@ -42,6 +43,9 @@ func (ActionCacheStatistics) Edges() []ent.Edge {
4243
Unique(),
4344

4445
// Breakdown of the cache misses based on the reasons behind them.
45-
edge.To("miss_details", MissDetail.Type),
46+
edge.To("miss_details", MissDetail.Type).
47+
Annotations(
48+
entsql.OnDelete(entsql.Cascade),
49+
),
4650
}
4751
}

ent/schema/actionsummary.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
"entgo.io/ent/schema/field"
78
)
@@ -46,13 +47,22 @@ func (ActionSummary) Edges() []ent.Edge {
4647
Unique(),
4748

4849
// Contains the top N actions by number of actions executed.
49-
edge.To("action_data", ActionData.Type),
50+
edge.To("action_data", ActionData.Type).
51+
Annotations(
52+
entsql.OnDelete(entsql.Cascade),
53+
),
5054

5155
// Count of which Runner types were executed which actions.
52-
edge.To("runner_count", RunnerCount.Type),
56+
edge.To("runner_count", RunnerCount.Type).
57+
Annotations(
58+
entsql.OnDelete(entsql.Cascade),
59+
),
5360

5461
// Information about the action cache behavior during a single invocation.
5562
edge.To("action_cache_statistics", ActionCacheStatistics.Type).
56-
Unique(),
63+
Unique().
64+
Annotations(
65+
entsql.OnDelete(entsql.Cascade),
66+
),
5767
}
5868
}

ent/schema/artifactmetrics.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
)
78

@@ -26,25 +27,37 @@ func (ArtifactMetrics) Edges() []ent.Edge {
2627
// Measures all source files newly read this build. Does not include
2728
// unchanged sources on incremental builds.
2829
edge.To("source_artifacts_read", FilesMetric.Type).
29-
Unique(),
30+
Unique().
31+
Annotations(
32+
entsql.OnDelete(entsql.Cascade),
33+
),
3034

3135
// Measures all output artifacts from executed actions. This includes
3236
// actions that were cached locally (via the action cache) or remotely (via
3337
// a remote cache or executor), but does *not* include outputs of actions
3438
// that were cached internally in Skyframe.
3539
edge.To("output_artifacts_seen", FilesMetric.Type).
36-
Unique(),
40+
Unique().
41+
Annotations(
42+
entsql.OnDelete(entsql.Cascade),
43+
),
3744

3845
// Measures all output artifacts from actions that were cached locally
3946
// via the action cache. These artifacts were already present on disk at the
4047
// start of the build. Does not include Skyframe-cached actions' outputs.
4148
edge.To("output_artifacts_from_action_cache", FilesMetric.Type).
42-
Unique(),
49+
Unique().
50+
Annotations(
51+
entsql.OnDelete(entsql.Cascade),
52+
),
4353

4454
// Measures all artifacts that belong to a top-level output group. Does not
4555
// deduplicate, so if there are two top-level targets in this build that
4656
// share an artifact, it will be counted twice.
4757
edge.To("top_level_artifacts", FilesMetric.Type).
48-
Unique(),
58+
Unique().
59+
Annotations(
60+
entsql.OnDelete(entsql.Cascade),
61+
),
4962
}
5063
}

ent/schema/bazelinvocation.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package schema
33
import (
44
"entgo.io/contrib/entgql"
55
"entgo.io/ent"
6+
"entgo.io/ent/dialect/entsql"
67
"entgo.io/ent/schema"
78
"entgo.io/ent/schema/edge"
89
"entgo.io/ent/schema/field"
@@ -99,21 +100,36 @@ func (BazelInvocation) Edges() []ent.Edge {
99100
// Edge to any probles detected.
100101
// NOTE: Uses custom resolver / types.
101102
edge.To("problems", BazelInvocationProblem.Type).
102-
Annotations(entgql.Skip(entgql.SkipType)),
103+
Annotations(
104+
entgql.Skip(entgql.SkipType),
105+
entsql.OnDelete(entsql.Cascade),
106+
),
103107

104108
// Build Metrics for the Completed Invocation
105109
edge.To("metrics", Metrics.Type).
110+
Annotations(
111+
entsql.OnDelete(entsql.Cascade),
112+
).
106113
Unique(),
107114

108115
// Test Data for the completed Invocation
109-
edge.To("test_collection", TestCollection.Type),
116+
edge.To("test_collection", TestCollection.Type).
117+
Annotations(
118+
entsql.OnDelete(entsql.Cascade),
119+
),
110120

111121
// Target Data for the completed Invocation
112-
edge.To("targets", TargetPair.Type),
122+
edge.To("targets", TargetPair.Type).
123+
Annotations(
124+
entsql.OnDelete(entsql.Cascade),
125+
),
113126

114127
// Edge to source control information
115128
edge.To("source_control", SourceControl.Type).
116-
Unique(),
129+
Unique().
130+
Annotations(
131+
entsql.OnDelete(entsql.Cascade),
132+
),
117133
}
118134
}
119135

ent/schema/build.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package schema
33
import (
44
"entgo.io/contrib/entgql"
55
"entgo.io/ent"
6+
"entgo.io/ent/dialect/entsql"
67
"entgo.io/ent/schema"
78
"entgo.io/ent/schema/edge"
89
"entgo.io/ent/schema/field"
@@ -28,7 +29,10 @@ func (Build) Fields() []ent.Field {
2829
// Edges of the Build.
2930
func (Build) Edges() []ent.Edge {
3031
return []ent.Edge{
31-
edge.To("invocations", BazelInvocation.Type),
32+
edge.To("invocations", BazelInvocation.Type).
33+
Annotations(
34+
entsql.OnDelete(entsql.Cascade),
35+
),
3236
}
3337
}
3438

ent/schema/buildgraphmetrics.go

+21-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
"entgo.io/ent/schema/field"
78
)
@@ -84,32 +85,47 @@ func (BuildGraphMetrics) Edges() []ent.Edge {
8485
// those that transitively depend on a node that changed by itself (e.g. one
8586
// representing a file in the file system)
8687
edge.To("dirtied_values", EvaluationStat.Type).
87-
Unique(),
88+
Unique().
89+
Annotations(
90+
entsql.OnDelete(entsql.Cascade),
91+
),
8892

8993
// Changed Values.
9094
// Number of SkyValues that changed by themselves. For example, when a file
9195
// on the file system changes, the SkyValue representing it will change.
9296
edge.To("changed_values", EvaluationStat.Type).
93-
Unique(),
97+
Unique().
98+
Annotations(
99+
entsql.OnDelete(entsql.Cascade),
100+
),
94101

95102
// Built Values.
96103
// Number of SkyValues that were built. This means that they were evaluated
97104
// and were found to have changed from their previous version.
98105
edge.To("built_values", EvaluationStat.Type).
99-
Unique(),
106+
Unique().
107+
Annotations(
108+
entsql.OnDelete(entsql.Cascade),
109+
),
100110

101111
// Cleaned Values.
102112
// Number of SkyValues that were evaluated and found clean, i.e. equal to
103113
// their previous version.
104114
edge.To("cleaned_values", EvaluationStat.Type).
105-
Unique(),
115+
Unique().
116+
Annotations(
117+
entsql.OnDelete(entsql.Cascade),
118+
),
106119

107120
// Evaluated Values.
108121
// Number of evaluations to build SkyValues. This includes restarted
109122
// evaluations, which means there can be multiple evaluations per built
110123
// SkyValue. Subtract built_values from this number to get the number of
111124
// restarted evaluations.
112125
edge.To("evaluated_values", EvaluationStat.Type).
113-
Unique(),
126+
Unique().
127+
Annotations(
128+
entsql.OnDelete(entsql.Cascade),
129+
),
114130
}
115131
}

ent/schema/dynamicexecutionmetrics.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
)
78

@@ -24,6 +25,9 @@ func (DynamicExecutionMetrics) Edges() []ent.Edge {
2425
Unique(),
2526

2627
// Race statistics grouped by mnemonic, local_name, remote_name.
27-
edge.To("race_statistics", RaceStatistics.Type),
28+
edge.To("race_statistics", RaceStatistics.Type).
29+
Annotations(
30+
entsql.OnDelete(entsql.Cascade),
31+
),
2832
}
2933
}

ent/schema/executioninfo.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
"entgo.io/ent/schema/field"
78
)
@@ -44,9 +45,15 @@ func (ExectionInfo) Edges() []ent.Edge {
4445
// Represents a hierarchical timing breakdown of an activity.
4546
// The top level time should be the total time of the activity.
4647
// Invariant: `time` >= sum of `time`s of all direct children.
47-
edge.To("timing_breakdown", TimingBreakdown.Type).Unique(),
48+
edge.To("timing_breakdown", TimingBreakdown.Type).Unique().
49+
Annotations(
50+
entsql.OnDelete(entsql.Cascade),
51+
),
4852

4953
// resource usage info
50-
edge.To("resource_usage", ResourceUsage.Type),
54+
edge.To("resource_usage", ResourceUsage.Type).
55+
Annotations(
56+
entsql.OnDelete(entsql.Cascade),
57+
),
5158
}
5259
}

ent/schema/memorymetrics.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema
22

33
import (
44
"entgo.io/ent"
5+
"entgo.io/ent/dialect/entsql"
56
"entgo.io/ent/schema/edge"
67
"entgo.io/ent/schema/field"
78
)
@@ -37,6 +38,9 @@ func (MemoryMetrics) Edges() []ent.Edge {
3738
Unique(),
3839

3940
// Metrics about garbage collection
40-
edge.To("garbage_metrics", GarbageMetrics.Type),
41+
edge.To("garbage_metrics", GarbageMetrics.Type).
42+
Annotations(
43+
entsql.OnDelete(entsql.Cascade),
44+
),
4145
}
4246
}

ent/schema/metrics.go

+41-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package schema
33
import (
44
"entgo.io/contrib/entgql"
55
"entgo.io/ent"
6+
"entgo.io/ent/dialect/entsql"
67
"entgo.io/ent/schema"
78
"entgo.io/ent/schema/edge"
89
)
@@ -27,43 +28,73 @@ func (Metrics) Edges() []ent.Edge {
2728

2829
// The action summmary with details about actions executed.
2930
edge.To("action_summary", ActionSummary.Type).
30-
Unique(),
31+
Unique().
32+
Annotations(
33+
entsql.OnDelete(entsql.Cascade),
34+
),
3135

3236
// Details about memory usage and garbage collections.
3337
edge.To("memory_metrics", MemoryMetrics.Type).
34-
Unique(),
38+
Unique().
39+
Annotations(
40+
entsql.OnDelete(entsql.Cascade),
41+
),
3542

3643
// Target metrics.
3744
edge.To("target_metrics", TargetMetrics.Type).
38-
Unique(),
45+
Unique().
46+
Annotations(
47+
entsql.OnDelete(entsql.Cascade),
48+
),
3949

4050
// Package metrics.
4151
edge.To("package_metrics", PackageMetrics.Type).
42-
Unique(),
52+
Unique().
53+
Annotations(
54+
entsql.OnDelete(entsql.Cascade),
55+
),
4356

4457
// Timing metrics.
4558
edge.To("timing_metrics", TimingMetrics.Type).
46-
Unique(),
59+
Unique().
60+
Annotations(
61+
entsql.OnDelete(entsql.Cascade),
62+
),
4763

4864
// Cumulative metrics.
4965
edge.To("cumulative_metrics", CumulativeMetrics.Type).
50-
Unique(),
66+
Unique().
67+
Annotations(
68+
entsql.OnDelete(entsql.Cascade),
69+
),
5170

5271
// Artifact metrics.
5372
edge.To("artifact_metrics", ArtifactMetrics.Type).
54-
Unique(),
73+
Unique().
74+
Annotations(
75+
entsql.OnDelete(entsql.Cascade),
76+
),
5577

5678
// Network metrics if available.
5779
edge.To("network_metrics", NetworkMetrics.Type).
58-
Unique(),
80+
Unique().
81+
Annotations(
82+
entsql.OnDelete(entsql.Cascade),
83+
),
5984

6085
// Dynamic execution metrics if available.
6186
edge.To("dynamic_execution_metrics", DynamicExecutionMetrics.Type).
62-
Unique(),
87+
Unique().
88+
Annotations(
89+
entsql.OnDelete(entsql.Cascade),
90+
),
6391

6492
// Build graph metrics.
6593
edge.To("build_graph_metrics", BuildGraphMetrics.Type).
66-
Unique(),
94+
Unique().
95+
Annotations(
96+
entsql.OnDelete(entsql.Cascade),
97+
),
6798
}
6899
}
69100

0 commit comments

Comments
 (0)