-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
733eb5b
commit 01049fd
Showing
19 changed files
with
987 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,3 @@ | |
go.work | ||
|
||
bin/ | ||
|
||
# Ignore any ent generated code in examples | ||
examples/* | ||
!examples/*/*.md | ||
!examples/*/schema/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Edge Schema | ||
|
||
Schema taken from: <https://github.com/ent/ent/tree/master/entc/integration/edgeschema> | ||
|
||
## Schema | ||
|
||
> **Note** | ||
> | ||
> The following schema was generated by `entmaid`. | ||
<!-- #start:entmaid --> | ||
```mermaid | ||
erDiagram | ||
Group { | ||
int id PK | ||
string name | ||
} | ||
group_users { | ||
int group_id PK,FK | ||
int user_id PK,FK | ||
} | ||
User { | ||
int id PK | ||
int age | ||
string name | ||
} | ||
Group |o--o{ group_users : users-groups | ||
User |o--o{ group_users : groups-users | ||
``` | ||
<!-- #end:entmaid --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
# Edge Schema | ||
|
||
Schema taken from: <https://github.com/ent/ent/tree/master/entc/integration/edgeschema> | ||
|
||
## Schema | ||
|
||
> **Note** | ||
> | ||
> The following schema was generated by `entmaid`. | ||
<!-- #start:entmaid --> | ||
```mermaid | ||
erDiagram | ||
AttachedFile { | ||
int id PK | ||
time-Time attach_time | ||
int f_id | ||
int proc_id | ||
} | ||
File { | ||
int id PK | ||
string name | ||
} | ||
Friendship { | ||
int id PK | ||
int weight | ||
time-Time created_at | ||
int user_id | ||
int friend_id | ||
} | ||
Group { | ||
int id PK | ||
string name | ||
} | ||
GroupTag { | ||
int id PK | ||
int tag_id | ||
int group_id | ||
} | ||
Process { | ||
int id PK | ||
} | ||
attached_files { | ||
int proc_id PK,FK | ||
int f_id PK,FK | ||
} | ||
Relationship { | ||
int weight | ||
int user_id | ||
int relative_id | ||
int info_id | ||
} | ||
RelationshipInfo { | ||
int id PK | ||
string text | ||
} | ||
Role { | ||
int id PK | ||
string name | ||
time-Time created_at | ||
} | ||
RoleUser { | ||
time-Time created_at | ||
int role_id | ||
int user_id | ||
} | ||
Tag { | ||
int id PK | ||
string value | ||
} | ||
tweet_tags { | ||
int tag_id PK,FK | ||
int tweet_id PK,FK | ||
} | ||
group_tags { | ||
int tag_id PK,FK | ||
int group_id PK,FK | ||
} | ||
Tweet { | ||
int id PK | ||
string text | ||
} | ||
TweetLike { | ||
time-Time liked_at | ||
int user_id | ||
int tweet_id | ||
} | ||
TweetTag { | ||
uuid-UUID id PK | ||
time-Time added_at | ||
int tag_id | ||
int tweet_id | ||
} | ||
User { | ||
int id PK | ||
string name | ||
} | ||
user_groups { | ||
int user_id PK,FK | ||
int group_id PK,FK | ||
} | ||
friendships { | ||
int user_id PK,FK | ||
int friend_id PK,FK | ||
} | ||
relationships { | ||
int user_id PK,FK | ||
int relative_id PK,FK | ||
} | ||
tweet_likes { | ||
int user_id PK,FK | ||
int tweet_id PK,FK | ||
} | ||
user_tweets { | ||
int user_id PK,FK | ||
int tweet_id PK,FK | ||
} | ||
role_users { | ||
int user_id PK,FK | ||
int role_id PK,FK | ||
} | ||
UserGroup { | ||
int id PK | ||
time-Time joined_at | ||
int user_id | ||
int group_id | ||
} | ||
UserTweet { | ||
int id PK | ||
time-Time created_at | ||
int user_id | ||
int tweet_id | ||
} | ||
AttachedFile }o--o| File : fi | ||
AttachedFile }o--o| Process : proc | ||
File |o--o{ attached_files : processes-files | ||
Friendship }o--o| User : user | ||
Friendship }o--o| User : friend | ||
Group |o--o{ user_groups : users-groups | ||
Group |o--o{ group_tags : tags-groups | ||
GroupTag }o--o| Tag : tag | ||
GroupTag }o--o| Group : group | ||
Process |o--o{ attached_files : files-processes | ||
Relationship }o--o| User : user | ||
Relationship }o--o| User : relative | ||
Relationship }o--o| RelationshipInfo : info | ||
Role |o--o{ role_users : user-roles | ||
RoleUser }o--o| Role : role | ||
RoleUser }o--o| User : user | ||
Tag |o--o{ tweet_tags : tweets-tags | ||
Tag |o--o{ group_tags : groups-tags | ||
Tweet |o--o{ tweet_likes : liked_users-liked_tweets | ||
Tweet |o--o{ user_tweets : user-tweets | ||
Tweet |o--o{ tweet_tags : tags-tweets | ||
TweetLike }o--o| Tweet : tweet | ||
TweetLike }o--o| User : user | ||
TweetTag }o--o| Tag : tag | ||
TweetTag }o--o| Tweet : tweet | ||
User |o--o{ user_groups : groups-users | ||
User |o--o{ friendships : friends | ||
User |o--o{ relationships : relatives | ||
User |o--o{ tweet_likes : liked_tweets-liked_users | ||
User |o--o{ user_tweets : tweets-user | ||
User |o--o{ role_users : roles-user | ||
UserGroup }o--o| User : user | ||
UserGroup }o--o| Group : group | ||
UserTweet }o--o| User : user | ||
UserTweet }o--o| Tweet : tweet | ||
``` | ||
<!-- #end:entmaid --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// 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. | ||
// | ||
// Code has been copied from the ent examples folder to demonstrate common schema patterns. | ||
// You can find the original code here: https://github.com/ent/ent/tree/master/entc/integration/edgeschema | ||
|
||
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"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
// | ||
// Code has been copied from the ent examples folder to demonstrate common schema patterns. | ||
// You can find the original code here: https://github.com/ent/ent/tree/master/entc/integration/edgeschema | ||
|
||
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), | ||
} | ||
} |
Oops, something went wrong.