Files
ent/entc/integration/ent/schema/file.go
Ariel Mashraki bd07c86b60 all: add license header to all go files
Summary:
Used addlicense to generate this:
 addlicense -c "Facebook Inc" -f license_header .

example was taken from: https://github.com/facebook/litho/blob/master/lib/soloader/BUCK

Reviewed By: alexsn

Differential Revision: D17070152

fbshipit-source-id: e7b91398d7f6181727be3400c1872ad5f28e38ed
2019-08-27 04:48:28 -07:00

63 lines
1.4 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package schema
import (
"math"
"github.com/facebookincubator/ent"
"github.com/facebookincubator/ent/schema/edge"
"github.com/facebookincubator/ent/schema/field"
"github.com/facebookincubator/ent/schema/index"
)
// File holds the schema definition for the File entity.
type File struct {
ent.Schema
}
// Fields of the File.
func (File) Fields() []ent.Field {
return []ent.Field{
field.Int("size").
Default(math.MaxInt32).
Positive(),
field.String("name"),
field.String("user").
Optional().
Nillable(),
field.String("group").
Optional(),
}
}
// Edges of the File.
func (File) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Ref("files").
Unique(),
edge.From("type", FileType.Type).
Ref("files").
Unique(),
}
}
// Indexes of a file.
func (File) Indexes() []ent.Index {
return []ent.Index{
// non-unique index should not prevent duplicates.
index.Fields("name", "size"),
// unique index prevents duplicates records.
index.Fields("name", "user").
Unique(),
// unique index under the "owner" sub-tree.
// user/owner can't have files with duplicate names.
index.Fields("name").
Edges("owner", "type").
Unique(),
}
}