Debian Codegraph @

ent/schema/attestationcollection.go

raw
1 // Copyright 2022 The Archivista Contributors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package schema
16
17 import (
18 "entgo.io/ent"
19 "entgo.io/ent/schema/edge"
20 "entgo.io/ent/schema/field"
21 "entgo.io/ent/schema/index"
22 "github.com/google/uuid"
23 )
24
25 // AttestationCollection represents a witness attestation collection
26 type AttestationCollection struct {
27 ent.Schema
28 }
29
30 func (AttestationCollection) Fields() []ent.Field {
31 return []ent.Field{
32 field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(),
33 field.String("name").NotEmpty(),
34 }
35 }
36
37 func (AttestationCollection) Edges() []ent.Edge {
38 return []ent.Edge{
39 edge.To("attestations", Attestation.Type),
40 edge.From("statement", Statement.Type).Ref("attestation_collections").Unique().Required(),
41 }
42 }
43
44 func (AttestationCollection) Indexes() []ent.Index {
45 return []ent.Index{
46 index.Fields("name"),
47 }
48 }