mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
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
63 lines
1.4 KiB
Go
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(),
|
|
}
|
|
}
|