snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
19
entc/integration/multischema/ent/schema/base.go
Normal file
19
entc/integration/multischema/ent/schema/base.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
)
|
||||
|
||||
// base holds the default configuration for most schemas in this package.
|
||||
type base struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the base schema.
|
||||
func (base) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Schema("db1"),
|
||||
}
|
||||
}
|
||||
65
entc/integration/multischema/ent/schema/friendship.go
Normal file
65
entc/integration/multischema/ent/schema/friendship.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"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"),
|
||||
}
|
||||
}
|
||||
|
||||
// Annotations of the Friendship.
|
||||
func (Friendship) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Schema("db2"),
|
||||
}
|
||||
}
|
||||
40
entc/integration/multischema/ent/schema/group.go
Normal file
40
entc/integration/multischema/ent/schema/group.go
Normal 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/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"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.To("users", User.Type),
|
||||
}
|
||||
}
|
||||
|
||||
// Annotations of the Group.
|
||||
func (Group) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Schema("db2"),
|
||||
}
|
||||
}
|
||||
44
entc/integration/multischema/ent/schema/parent.go
Normal file
44
entc/integration/multischema/ent/schema/parent.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// Parent holds the schema definition for the Parent entity.
|
||||
type Parent struct {
|
||||
base
|
||||
}
|
||||
|
||||
// Fields of the Parent.
|
||||
func (Parent) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Bool("by_adoption").
|
||||
Default(false),
|
||||
field.Int("user_id").
|
||||
Immutable(),
|
||||
field.Int("parent_id").
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Parent.
|
||||
func (Parent) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("child", User.Type).
|
||||
Unique().
|
||||
Required().
|
||||
Immutable().
|
||||
Field("user_id"),
|
||||
edge.To("parent", User.Type).
|
||||
Unique().
|
||||
Required().
|
||||
Immutable().
|
||||
Field("parent_id"),
|
||||
}
|
||||
}
|
||||
36
entc/integration/multischema/ent/schema/pet.go
Normal file
36
entc/integration/multischema/ent/schema/pet.go
Normal 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"
|
||||
)
|
||||
|
||||
// Pet holds the schema definition for the Pet entity.
|
||||
type Pet struct {
|
||||
base
|
||||
}
|
||||
|
||||
// Fields of the Pet.
|
||||
func (Pet) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Default("unknown"),
|
||||
field.Int("owner_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Pet.
|
||||
func (Pet) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("pets").
|
||||
Field("owner_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
60
entc/integration/multischema/ent/schema/user.go
Normal file
60
entc/integration/multischema/ent/schema/user.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// 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 {
|
||||
base
|
||||
}
|
||||
|
||||
// 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("pets", Pet.Type),
|
||||
edge.From("groups", Group.Type).
|
||||
Ref("users"),
|
||||
edge.To("friends", User.Type).
|
||||
Through("friendships", Friendship.Type),
|
||||
edge.To("children", User.Type).
|
||||
Through("parent_hood", Parent.Type).
|
||||
From("parents"),
|
||||
}
|
||||
}
|
||||
|
||||
// CleanUser represents a user without its PII field.
|
||||
type CleanUser struct {
|
||||
ent.View
|
||||
}
|
||||
|
||||
// Annotations of the CleanUser.
|
||||
func (CleanUser) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.View("SELECT id, name FROM users"),
|
||||
entsql.Schema("db1"),
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the CleanUser.
|
||||
func (CleanUser) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user