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,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/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
)
// Card holds the schema definition for the Card entity.
type Card struct {
ent.Schema
}
// Fields of the Card.
func (Card) Fields() []ent.Field {
return []ent.Field{
field.String("type").
Default("unknown"),
field.String("number_hash"),
field.String("cvv_hash"),
field.Time("expires_at").
Optional(),
field.Int("owner_id").
Default(0),
}
}
// Edges of the Card.
func (Card) Edges() []ent.Edge {
return []ent.Edge{
edge.From("owner", User.Type).
Ref("cards").
Unique().
Required().
Field("owner_id"),
edge.To("payments", Payment.Type),
}
}
// Annotations of the Card.
func (Card) Annotations() []schema.Annotation {
return []schema.Annotation{
// Named check constraints are compared by their name.
// Thus, the definition does not need to be normalized.
entsql.Checks(map[string]string{
"number_hash_length": "(LENGTH(`number_hash`) = 16)",
}),
}
}

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 (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// Payment holds the schema definition for the Payment entity.
type Payment struct {
ent.Schema
}
// Fields of the Payment.
func (Payment) Fields() []ent.Field {
return []ent.Field{
field.Int("card_id"),
field.Float("amount").
Positive(),
field.Enum("currency").
Values("USD", "EUR", "VND", "ILS"),
field.Time("time"),
field.String("description"),
field.Enum("status").
Values("pending", "completed", "failed"),
}
}
// Edges of the Payment.
func (Payment) Edges() []ent.Edge {
return []ent.Edge{
edge.From("card", Card.Type).
Ref("payments").
Unique().
Required().
Field("card_id"),
}
}
// Indexes of the Payment.
func (Payment) Indexes() []ent.Index {
return []ent.Index{
index.Fields("status", "time"),
}
}
// Annotations of the Payment.
func (Payment) Annotations() []schema.Annotation {
return []schema.Annotation{
// Named check constraints are compared by their name.
// Thus, the definition does not need to be normalized.
entsql.Checks(map[string]string{
"amount_positive": "(`amount` > 0)",
}),
}
}

View File

@@ -0,0 +1,58 @@
// 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/dialect/entsql"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/google/uuid"
)
// Pet holds the schema definition for the Pet entity.
type Pet struct {
ent.Schema
}
// Fields of the Pet.
func (Pet) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.Nil).
Default(uuid.New),
field.String("name"),
field.Float("age"),
field.Float("weight"),
field.UUID("best_friend_id", uuid.Nil).
Annotations(
entsql.Default(uuid.Nil.String()),
),
field.Int("owner_id").
Default(0),
}
}
// Edges of the Pet.
func (Pet) Edges() []ent.Edge {
return []ent.Edge{
edge.To("best_friend", Pet.Type).
Unique().
Required().
Field("best_friend_id"),
edge.To("owner", User.Type).
Unique().
Required().
Field("owner_id"),
}
}
// Indexes of the Pet.
func (Pet) Indexes() []ent.Index {
return []ent.Index{
index.Fields("name", "owner_id").
Unique(),
}
}

View File

@@ -0,0 +1,100 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/google/uuid"
)
// Session holds the schema definition for the Session entity.
type Session struct {
ent.Schema
}
// Fields of the Session.
func (Session) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.Nil).
Default(uuid.New),
field.Bool("active").
Default(false),
field.Time("issued_at"),
field.Time("expires_at").
Optional(),
field.String("token").
Optional(),
field.JSON("method", map[string]any{}).
Optional(),
field.UUID("device_id", uuid.Nil).
Optional(),
}
}
// Edges of the Session.
func (Session) Edges() []ent.Edge {
return []ent.Edge{
edge.From("device", SessionDevice.Type).
Ref("sessions").
Unique().
Field("device_id"),
}
}
// Indexes of the Session.
func (Session) Indexes() []ent.Index {
return []ent.Index{
index.Fields("active", "expires_at"),
}
}
// Annotations of the Session.
func (Session) Annotations() []schema.Annotation {
return []schema.Annotation{
// Named check constraints are compared by their name.
// Thus, the definition does not need to be normalized.
entsql.Checks(map[string]string{
"token_length": "(LENGTH(`token`) = 64)",
}),
}
}
// SessionDevice holds the schema definition for the SessionDevice entity.
type SessionDevice struct {
ent.Schema
}
// Fields of the SessionDevice.
func (SessionDevice) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.Nil).
Default(uuid.New),
field.String("ip_address").
MaxLen(50),
field.String("user_agent").
MaxLen(512),
field.String("location").
MaxLen(512),
field.Time("created_at"),
field.Time("updated_at").
Optional(),
}
}
// Edges of the SessionDevice.
func (SessionDevice) Edges() []ent.Edge {
return []ent.Edge{
edge.To("sessions", Session.Type),
}
}
// Indexes of the SessionDevice.
func (SessionDevice) Indexes() []ent.Index {
return []ent.Index{
index.Fields("ip_address", "user_agent"),
index.Fields("location", "updated_at"),
}
}

View File

@@ -0,0 +1,52 @@
// 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/dialect/entsql"
"entgo.io/ent/schema"
"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.Float("age"),
field.String("first_name"),
field.String("last_name"),
field.Strings("tags").
Optional(),
}
}
// Annotations of the User.
func (User) Annotations() []schema.Annotation {
return []schema.Annotation{
// In case schema.ModeInspect is used without a dev-database, unnamed check constraints
// should be normalized (i.e. identical to their definition in the database). In this
// case, it is entsql.Check("(`age` > 0)"). See: https://atlasgo.io/concepts/dev-database.
entsql.Check("age > 0"),
// Named check constraints are compared by their name.
// Thus, the definition does not need to be normalized.
entsql.Checks(map[string]string{
"first_last_not_empty": "(`first_name` <> '' AND `last_name` <> '')",
}),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("cards", Card.Type),
}
}