ent seteup
This commit is contained in:
35
db/ent/schema/accesscontrol.go
Normal file
35
db/ent/schema/accesscontrol.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// AccessControl holds the schema definition for the AccessControl entity.
|
||||
type AccessControl struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the AccessControl.
|
||||
func (AccessControl) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
fieldID,
|
||||
fieldCreated,
|
||||
fieldUpdated,
|
||||
field.String("ptype").Default(""),
|
||||
field.String("v0").Default(""),
|
||||
field.String("v1").Default(""),
|
||||
field.String("v2").Default(""),
|
||||
field.String("v3").Default(""),
|
||||
field.String("v4").Default(""),
|
||||
field.String("v5").Default(""),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the AccessControl.
|
||||
func (AccessControl) Index() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("ptype", "v0", "v1", "v2", "v3", "v4", "v5").Unique(),
|
||||
}
|
||||
}
|
41
db/ent/schema/audit.go
Normal file
41
db/ent/schema/audit.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Audit holds the schema definition for the Audit entity.
|
||||
type Audit struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Audit.
|
||||
func (Audit) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
fieldID,
|
||||
fieldCreated,
|
||||
field.String("ent_name").MaxLen(50),
|
||||
field.Int64("ent_id").Positive(),
|
||||
field.Enum("operation").Values("Create", "Update", "UpdateOne", "Delete", "DeleteOne"),
|
||||
field.String("description").MaxLen(1000),
|
||||
field.String("ip").MaxLen(40).Optional(),
|
||||
field.String("user_name").MaxLen(150).Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Audit) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("ent_name", "ent_id"),
|
||||
index.Fields("operation"),
|
||||
index.Fields("ip"),
|
||||
}
|
||||
}
|
||||
|
||||
func (Audit) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).Ref("audit_logs").Unique(),
|
||||
}
|
||||
}
|
19
db/ent/schema/role.go
Normal file
19
db/ent/schema/role.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"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{
|
||||
fieldID,
|
||||
field.String("name"),
|
||||
}
|
||||
}
|
36
db/ent/schema/schema.go
Normal file
36
db/ent/schema/schema.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/contrib/entgql"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var fieldID = field.Int64("id").
|
||||
Immutable().
|
||||
Unique()
|
||||
|
||||
var fieldCreated = field.Time("created_at").
|
||||
Immutable().
|
||||
Default(time.Now).
|
||||
StructTag(`json:"createdAt"`).
|
||||
Annotations(
|
||||
entgql.OrderField("created"),
|
||||
)
|
||||
|
||||
var fieldUpdated = field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
UpdateDefault(time.Now).
|
||||
StructTag(`json:"updatedAt"`).
|
||||
Annotations(
|
||||
entgql.OrderField("updated"),
|
||||
)
|
||||
|
||||
var fieldDeleted = field.Time("deleted_at").
|
||||
Optional().
|
||||
Nillable().
|
||||
StructTag(`json:"deletedAt"`).
|
||||
Annotations(
|
||||
entgql.OrderField("deleted"),
|
||||
)
|
18
db/ent/schema/todo.go
Normal file
18
db/ent/schema/todo.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package schema
|
||||
|
||||
import "entgo.io/ent"
|
||||
|
||||
// Todo holds the schema definition for the Todo entity.
|
||||
type Todo struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Todo.
|
||||
func (Todo) Fields() []ent.Field {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edges of the Todo.
|
||||
func (Todo) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
53
db/ent/schema/user.go
Normal file
53
db/ent/schema/user.go
Normal file
@@ -0,0 +1,53 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// 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{
|
||||
fieldID,
|
||||
fieldCreated,
|
||||
fieldUpdated,
|
||||
field.String("email").Unique().NotEmpty(),
|
||||
field.Bool("email_verified").Default(false),
|
||||
field.String("phone").MaxLen(20),
|
||||
field.Bool("phone_verified").Default(false),
|
||||
field.String("pwd_salt").NotEmpty(),
|
||||
field.String("pwd_hash").NotEmpty(),
|
||||
field.Uint8("login_failed_count").Optional().Default(0),
|
||||
field.Time("login_attempt_on").Optional().Nillable(),
|
||||
field.Time("login_locked_until").Optional().Nillable(),
|
||||
field.String("first_name").MaxLen(30),
|
||||
field.String("middle_name").MaxLen(30).Nillable(),
|
||||
field.String("last_name").MaxLen(30),
|
||||
field.Enum("status").Values("Pending", "Active", "InActive").Default("Pending"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("sessions", UserSession.Type).StorageKey(edge.Column("user_id")),
|
||||
edge.To("audit_logs", Audit.Type).StorageKey(edge.Column("user_id")),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("created_at").Annotations(entsql.Desc()),
|
||||
index.Fields("updated_at").Annotations(entsql.Desc()),
|
||||
index.Fields("phone"),
|
||||
index.Fields("status"),
|
||||
}
|
||||
}
|
40
db/ent/schema/usersession.go
Normal file
40
db/ent/schema/usersession.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// UserSession holds the schema definition for the UserSession entity.
|
||||
type UserSession struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the UserSession.
|
||||
func (UserSession) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
fieldID,
|
||||
field.Time("issued_at"),
|
||||
field.Time("expires_at"),
|
||||
field.Bool("invalidated").Optional().Default(false),
|
||||
field.String("user_agent").MaxLen(50),
|
||||
field.String("ip").MaxLen(40),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the UserSession.
|
||||
func (UserSession) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).Ref("sessions").Unique().Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (UserSession) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("expires_at"),
|
||||
index.Fields("invalidated"),
|
||||
index.Fields("ip"),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user