Debian Codegraph @

ent/schema/signature.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/dialect"
20 "entgo.io/ent/schema/edge"
21 "entgo.io/ent/schema/field"
22 "entgo.io/ent/schema/index"
23 "github.com/google/uuid"
24 )
25
26 // Signature represents signatures on a DSSE envelope
27 type Signature struct {
28 ent.Schema
29 }
30
31 // Fields of the Signature.
32 func (Signature) Fields() []ent.Field {
33 return []ent.Field{
34 field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(),
35 field.String("key_id"),
36 field.String("signature").NotEmpty().SchemaType(map[string]string{dialect.MySQL: "text"}),
37 }
38 }
39
40 // Edges of the Signature.
41 func (Signature) Edges() []ent.Edge {
42 return []ent.Edge{
43 edge.From("dsse", Dsse.Type).Ref("signatures").Unique(),
44 edge.To("timestamps", Timestamp.Type),
45 }
46 }
47
48 func (Signature) Indexes() []ent.Index {
49 return []ent.Index{
50 index.Fields("key_id"),
51 }
52 }