snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 22:12:36 +05:00
commit 4b3ad0b611
2680 changed files with 719472 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Friendship holds the edge schema definition of the Friendship relationship.
type Friendship struct {
ent.Schema
}
// Fields of the Friendship.
func (Friendship) Fields() []ent.Field {
return []ent.Field{
field.Int("weight").
Default(1),
field.Time("created_at").
Default(time.Now),
field.Int("user_id").
Immutable(),
field.Int("friend_id").
Immutable(),
}
}
// Edges of the Friendship.
func (Friendship) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Unique().
Required().
Immutable().
Field("user_id"),
edge.To("friend", User.Type).
Unique().
Required().
Immutable().
Field("friend_id"),
}
}
// Indexes of the Friendship.
func (Friendship) Indexes() []ent.Index {
return []ent.Index{
index.Fields("created_at"),
// By default, Ent generates a unique index named <T>_<FK1>_<FK2>
// for edge-schemas with an ID field to enforce the uniqueness of
// the edges reside in the join table. However, in this case it is
// skipped because we define it explicitly in the definition below.
index.Fields("user_id", "friend_id").
Unique().
StorageKey("friendships_edge"),
}
}

View File

@@ -0,0 +1,36 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Group holds the schema definition for the Group entity.
type Group struct {
ent.Schema
}
// Fields of the Group.
func (Group) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("Unknown"),
}
}
// Edges of the Group.
func (Group) Edges() []ent.Edge {
return []ent.Edge{
edge.From("users", User.Type).
Ref("groups").
Through("joined_users", UserGroup.Type),
edge.From("tags", Tag.Type).
Ref("groups").
Through("group_tags", GroupTag.Type),
}
}

View File

@@ -0,0 +1,40 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// GroupTag holds the schema definition for the GroupTag entity.
type GroupTag struct {
ent.Schema
}
// Fields of the GroupTag.
func (GroupTag) Fields() []ent.Field {
return []ent.Field{
// An edge schema with the builtin ID
// field, but without any other field.
field.Int("tag_id"),
field.Int("group_id"),
}
}
// Edges of the GroupTag.
func (GroupTag) Edges() []ent.Edge {
return []ent.Edge{
edge.To("tag", Tag.Type).
Unique().
Required().
Field("tag_id"),
edge.To("group", Group.Type).
Unique().
Required().
Field("group_id"),
}
}

View File

@@ -0,0 +1,81 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// An example for an edge-schema (AttachedFile) that uses a custom name for its edges
// (not foreign-keys) and Ent matches by the schema types and not foreign-key names.
// Process holds the edge schema definition of the Process relationship.
type Process struct {
ent.Schema
}
// Edges of the Process.
func (Process) Edges() []ent.Edge {
return []ent.Edge{
edge.To("files", File.Type).
Through("attached_files", AttachedFile.Type).
Comment("Files that were attached by this process"),
}
}
// File holds the edge schema definition of the File relationship.
type File struct {
ent.Schema
}
// Fields of the File.
func (File) Fields() []ent.Field {
return []ent.Field{
field.String("name"),
}
}
// Edges of the File.
func (File) Edges() []ent.Edge {
return []ent.Edge{
edge.From("processes", Process.Type).
Ref("files"),
}
}
// AttachedFile holds the edge schema definition of the File relationship.
type AttachedFile struct {
ent.Schema
}
// Fields of the AttachedFile.
func (AttachedFile) Fields() []ent.Field {
return []ent.Field{
field.Time("attach_time").
Default(time.Now),
field.Int("f_id"),
field.Int("proc_id"),
}
}
// Edges of the AttachedFile.
func (AttachedFile) Edges() []ent.Edge {
return []ent.Edge{
// Note: the two following edges use different name conventions (e.g., f_id <> file_id), but
// Ent knows how to resolve this as there is only one usage of each type in this declaration.
edge.To("fi", File.Type).
Required().
Unique().
Field("f_id"),
edge.To("proc", Process.Type).
Required().
Unique().
Field("proc_id"),
}
}

View File

@@ -0,0 +1,87 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/entc/integration/edgeschema/ent/privacy"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Relationship holds the schema definition for the Relationship entity.
type Relationship struct {
ent.Schema
}
func (Relationship) Annotations() []schema.Annotation {
return []schema.Annotation{
field.ID("user_id", "relative_id"),
}
}
// Fields of the Relationship.
func (Relationship) Fields() []ent.Field {
return []ent.Field{
field.Int("weight").
Default(1),
// Edge fields for the fields that compose this edge.
// They also function as the primary key of the table.
field.Int("user_id"),
field.Int("relative_id"),
// An edge field to external node that holds
// additional information about this edge.
field.Int("info_id").
Optional(),
}
}
// Edges of the Relationship.
func (Relationship) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Required().
Unique().
Field("user_id"),
edge.To("relative", User.Type).
Required().
Unique().
Field("relative_id"),
// An optional edge to an entity that holds
// information about this relationship.
edge.To("info", RelationshipInfo.Type).
Field("info_id").
Unique(),
}
}
// Indexes of the Relationship.
func (Relationship) Indexes() []ent.Index {
return []ent.Index{
index.Fields("weight"),
// A relationship-info can be connected to no more
// than one relationship object (and edge schema).
index.Edges("info").
Unique(),
}
}
// Policy defines the privacy policy of the Relationship.
func (Relationship) Policy() ent.Policy {
return privacy.Policy{
Mutation: privacy.MutationPolicy{
privacy.AlwaysAllowRule(),
},
Query: privacy.QueryPolicy{
privacy.AlwaysAllowRule(),
},
}
}

View File

@@ -0,0 +1,22 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/field"
)
// RelationshipInfo holds the schema definition for the RelationshipInfo entity.
type RelationshipInfo struct {
ent.Schema
}
// Fields of the RelationshipInfo.
func (RelationshipInfo) Fields() []ent.Field {
return []ent.Field{
field.String("text"),
}
}

View File

@@ -0,0 +1,37 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Role holds the schema definition for the Role entity.
type Role struct {
ent.Schema
}
// Fields of the Role.
func (Role) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Unique(),
field.Time("created_at").
Default(time.Now),
}
}
// Edges of the Role.
func (Role) Edges() []ent.Edge {
return []ent.Edge{
edge.From("user", User.Type).
Ref("roles").
Through("roles_users", RoleUser.Type),
}
}

View File

@@ -0,0 +1,50 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// RoleUser holds the schema definition for the RoleUser entity.
type RoleUser struct {
ent.Schema
}
func (RoleUser) Annotations() []schema.Annotation {
return []schema.Annotation{
field.ID("user_id", "role_id"),
}
}
// Fields of the RoleUser.
func (RoleUser) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").
Default(time.Now),
// Edge fields.
field.Int("role_id"),
field.Int("user_id"),
}
}
// Edges of the RoleUser.
func (RoleUser) Edges() []ent.Edge {
return []ent.Edge{
edge.To("role", Role.Type).
Unique().
Required().
Field("role_id"),
edge.To("user", User.Type).
Unique().
Required().
Field("user_id"),
}
}

View File

@@ -0,0 +1,33 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Tag holds the schema definition for the Tag entity.
type Tag struct {
ent.Schema
}
// Fields of the Tag.
func (Tag) Fields() []ent.Field {
return []ent.Field{
field.String("value"),
}
}
// Edges of the Tag.
func (Tag) Edges() []ent.Edge {
return []ent.Edge{
edge.To("tweets", Tweet.Type).
Through("tweet_tags", TweetTag.Type),
edge.To("groups", Group.Type).
Through("group_tags", GroupTag.Type),
}
}

View File

@@ -0,0 +1,39 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Tweet holds the schema definition for the Tweet entity.
type Tweet struct {
ent.Schema
}
// Fields of the Tweet.
func (Tweet) Fields() []ent.Field {
return []ent.Field{
field.Text("text"),
}
}
// Edges of the Tweet.
func (Tweet) Edges() []ent.Edge {
return []ent.Edge{
edge.From("liked_users", User.Type).
Ref("liked_tweets").
Through("likes", TweetLike.Type),
edge.From("user", User.Type).
Ref("tweets").
Through("tweet_user", UserTweet.Type).
Comment("The uniqueness is enforced on the edge schema"),
edge.From("tags", Tag.Type).
Ref("tweets").
Through("tweet_tags", TweetTag.Type),
}
}

View File

@@ -0,0 +1,62 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/entc/integration/edgeschema/ent/privacy"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// TweetLike holds the schema definition for the TweetLike entity.
type TweetLike struct {
ent.Schema
}
func (TweetLike) Annotations() []schema.Annotation {
return []schema.Annotation{
field.ID("user_id", "tweet_id"),
}
}
// Fields of the TweetLike.
func (TweetLike) Fields() []ent.Field {
return []ent.Field{
field.Time("liked_at").
Default(time.Now),
field.Int("user_id"),
field.Int("tweet_id"),
}
}
// Edges of the TweetLike.
func (TweetLike) Edges() []ent.Edge {
return []ent.Edge{
edge.To("tweet", Tweet.Type).
Unique().
Required().
Field("tweet_id"),
edge.To("user", User.Type).
Unique().
Required().
Field("user_id"),
}
}
// Policy defines the privacy policy of the TweetLike.
func (TweetLike) Policy() ent.Policy {
return privacy.Policy{
Mutation: privacy.MutationPolicy{
privacy.AlwaysAllowRule(),
},
Query: privacy.QueryPolicy{
privacy.AlwaysAllowRule(),
},
}
}

View File

@@ -0,0 +1,45 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// TweetTag holds the schema definition for the TweetTag entity.
type TweetTag struct {
ent.Schema
}
// Fields of the TweetTag.
func (TweetTag) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Default(uuid.New),
field.Time("added_at").
Default(time.Now),
field.Int("tag_id"),
field.Int("tweet_id"),
}
}
// Edges of the TweetTag.
func (TweetTag) Edges() []ent.Edge {
return []ent.Edge{
edge.To("tag", Tag.Type).
Unique().
Required().
Field("tag_id"),
edge.To("tweet", Tweet.Type).
Unique().
Required().
Field("tweet_id"),
}
}

View File

@@ -0,0 +1,55 @@
// 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 (
"entgo.io/ent"
"entgo.io/ent/entc/integration/privacy/ent/privacy"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("Unknown"),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("groups", Group.Type).
Through("joined_groups", UserGroup.Type),
edge.To("friends", User.Type).
Through("friendships", Friendship.Type),
edge.To("relatives", User.Type).
Through("relationship", Relationship.Type),
edge.To("liked_tweets", Tweet.Type).
Through("likes", TweetLike.Type),
edge.To("tweets", Tweet.Type).
Through("user_tweets", UserTweet.Type),
edge.To("roles", Role.Type).
Through("roles_users", RoleUser.Type),
}
}
// Policy defines the privacy policy of the User.
func (User) Policy() ent.Policy {
return privacy.Policy{
Mutation: privacy.MutationPolicy{
privacy.AlwaysAllowRule(),
},
Query: privacy.QueryPolicy{
privacy.AlwaysAllowRule(),
},
}
}

View File

@@ -0,0 +1,42 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// UserGroup holds the schema definition for the UserGroup entity.
type UserGroup struct {
ent.Schema
}
// Fields of the UserGroup.
func (UserGroup) Fields() []ent.Field {
return []ent.Field{
field.Time("joined_at").
Default(time.Now),
field.Int("user_id"),
field.Int("group_id"),
}
}
// Edges of the UserGroup.
func (UserGroup) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Unique().
Required().
Field("user_id"),
edge.To("group", Group.Type).
Unique().
Required().
Field("group_id"),
}
}

View File

@@ -0,0 +1,51 @@
// 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 (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// UserTweet holds the schema definition for the UserTweet entity.
type UserTweet struct {
ent.Schema
}
// Fields of the UserTweet.
func (UserTweet) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").
Default(time.Now),
field.Int("user_id"),
field.Int("tweet_id"),
}
}
// Edges of the UserTweet.
func (UserTweet) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Unique().
Required().
Field("user_id"),
edge.To("tweet", Tweet.Type).
Unique().
Required().
Field("tweet_id"),
}
}
// Indexes of the UserTweet.
func (UserTweet) Indexes() []ent.Index {
return []ent.Index{
index.Fields("tweet_id").
Unique(),
}
}